tests (#8)
This commit is contained in:
		
							parent
							
								
									2c4932a941
								
							
						
					
					
						commit
						e0f4656544
					
				
					 2 changed files with 88 additions and 6 deletions
				
			
		
							
								
								
									
										10
									
								
								.github/workflows/ci.yml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								.github/workflows/ci.yml
									
										
									
									
										vendored
									
									
								
							|  | @ -29,11 +29,13 @@ jobs: | |||
|     - name: install wasm-pack | ||||
|       run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | ||||
| 
 | ||||
|     - name: check | ||||
|       run: cargo check | ||||
|     - run: cargo check | ||||
| 
 | ||||
|     - name: test | ||||
|       run: wasm-pack test --node | ||||
|     - run: cargo test | ||||
| 
 | ||||
|     - run: wasm-pack test --headless --firefox | ||||
| 
 | ||||
|     - run: wasm-pack test --headless --chrome | ||||
| 
 | ||||
|   build: | ||||
|     runs-on: ubuntu-latest | ||||
|  |  | |||
							
								
								
									
										84
									
								
								tests/web.rs
									
										
									
									
									
								
							
							
						
						
									
										84
									
								
								tests/web.rs
									
										
									
									
									
								
							|  | @ -8,6 +8,86 @@ use wasm_bindgen_test::*; | |||
| wasm_bindgen_test_configure!(run_in_browser); | ||||
| 
 | ||||
| #[wasm_bindgen_test] | ||||
| fn pass() { | ||||
|     assert_eq!(1 + 1, 2); | ||||
| fn basic_merge() { | ||||
|     // arrange
 | ||||
|     let array: js_sys::Array = js_sys::Array::new(); | ||||
|     let file1 = wasm_bindgen::JsValue::from_str( | ||||
|         "<?xml version='1.0' encoding='utf-8'?>
 | ||||
|          <gpx version='1.0' encoding='UTF-8'> | ||||
|            <trk> | ||||
|              <name>file1 tracks</name> | ||||
|              <type>1</type> | ||||
|              <trkseg> | ||||
|                <trkpt lat='35.466388' lon='-111.640076'> | ||||
|                  <ele>2152.8</ele> | ||||
|                  <time>2020-09-27T15:39:27+00:00</time> | ||||
|                </trkpt> | ||||
|              </trkseg> | ||||
|            </trk> | ||||
|          </gpx>",
 | ||||
|     ); | ||||
|     let file2 = wasm_bindgen::JsValue::from_str( | ||||
|         "<?xml version='1.0' encoding='utf-8'?>
 | ||||
|          <gpx version='1.0' encoding='UTF-8'> | ||||
|            <trk> | ||||
|              <name>file2 tracks</name> | ||||
|              <type>1</type> | ||||
|              <trkseg> | ||||
|                <trkpt lat='35.339854' lon='-111.737165'> | ||||
|                  <ele>2556.8</ele> | ||||
|                  <time>2020-09-26T19:07:14+00:00</time> | ||||
|                </trkpt> | ||||
|              </trkseg> | ||||
|            </trk> | ||||
|          </gpx>",
 | ||||
|     ); | ||||
|     array.push(&file1); | ||||
|     array.push(&file2); | ||||
| 
 | ||||
|     let exp = wasm_bindgen::JsValue::from_str( | ||||
|         "<?xml version=\"1.0\" encoding=\"utf-8\"?>
 | ||||
| <gpx version=\"1.1\" creator=\"https://github.com/georust/gpx\">
 | ||||
|   <metadata> | ||||
|     <name>merged</name> | ||||
|     <author> | ||||
|       <link href=\"https://gpx.thermokar.st\" />
 | ||||
|     </author> | ||||
|   </metadata> | ||||
|   <trk> | ||||
|     <name>file1 tracks</name> | ||||
|     <type>1</type> | ||||
|     <trkseg> | ||||
|       <trkpt lat=\"35.466388\" lon=\"-111.640076\">
 | ||||
|         <ele>2152.8</ele> | ||||
|         <time>2020-09-27T15:39:27+00:00</time> | ||||
|       </trkpt> | ||||
|     </trkseg> | ||||
|   </trk> | ||||
|   <trk> | ||||
|     <name>file2 tracks</name> | ||||
|     <type>1</type> | ||||
|     <trkseg> | ||||
|       <trkpt lat=\"35.339854\" lon=\"-111.737165\">
 | ||||
|         <ele>2556.8</ele> | ||||
|         <time>2020-09-26T19:07:14+00:00</time> | ||||
|       </trkpt> | ||||
|     </trkseg> | ||||
|   </trk> | ||||
|   <rte /> | ||||
| </gpx>",
 | ||||
|     ); | ||||
| 
 | ||||
|     // act
 | ||||
|     let obs = gpx_web_utils::merge(array); | ||||
| 
 | ||||
|     // assert
 | ||||
|     assert_eq!(obs, exp); | ||||
| } | ||||
| 
 | ||||
| // TODO: https://github.com/rustwasm/wasm-bindgen/issues/2286
 | ||||
| // #[wasm_bindgen_test]
 | ||||
| // #[should_panic]
 | ||||
| // fn invalid_inputs() {
 | ||||
| //     let array: js_sys::Array = js_sys::Array::new_with_length(10);
 | ||||
| //     let obs = gpx_web_utils::merge(array);
 | ||||
| // }
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 GitHub
							GitHub