forked from MapComplete/MapComplete
		
	Huge refactorings of JSON-parsing and Tagsfilter, other cleanups, warning cleanups and lots of small subtle bugfixes
This commit is contained in:
		
							parent
							
								
									9a5b35b9f3
								
							
						
					
					
						commit
						a57b7d93fa
					
				
					 113 changed files with 1565 additions and 2594 deletions
				
			
		|  | @ -1,29 +1,17 @@ | |||
| import {equal} from "assert"; | ||||
| import {UIElement} from "../UI/UIElement"; | ||||
| 
 | ||||
| UIElement.runningFromConsole = true; | ||||
| import {CustomLayoutFromJSON} from "../Customizations/JSON/CustomLayoutFromJSON"; | ||||
| import {And} from "../Logic/TagsFilter"; | ||||
| 
 | ||||
| import {equal} from "assert"; | ||||
| import Translation from "../UI/i18n/Translation"; | ||||
| import T from "./TestHelper"; | ||||
| import {FromJSON} from "../Customizations/JSON/FromJSON"; | ||||
| import {And, Tag} from "../Logic/Tags"; | ||||
| import Locale from "../UI/i18n/Locale"; | ||||
| import Translations from "../UI/i18n/Translations"; | ||||
| 
 | ||||
| 
 | ||||
| new T([ | ||||
|     ["Parse and match advanced tagging", () => { | ||||
|         const tags = CustomLayoutFromJSON.TagsFromJson("indoor=yes&access!=private"); | ||||
|         const m0 = new And(tags).matches([{k: "indoor", v: "yes"}, {k: "access", v: "yes"}]); | ||||
|         equal(m0, true); | ||||
|         const m1 = new And(tags).matches([{k: "indoor", v: "yes"}, {k: "access", v: "private"}]); | ||||
|         equal(m1, false); | ||||
|     } | ||||
|     ], | ||||
|     ["Parse tagging with regex", () => { | ||||
|         const tags = CustomLayoutFromJSON.TagsFromJson("highway~=residential|tertiary"); | ||||
|         equal(""+tags[0].value, ""+/residential|tertiary/); | ||||
|         console.log(tags[0].asOverpass()); | ||||
| 
 | ||||
|     } | ||||
|     ], | ||||
|     ["Tag replacement works in translation", () => { | ||||
|         const tr = new Translation({ | ||||
|             "en": "Test {key} abc" | ||||
|  | @ -31,6 +19,50 @@ new T([ | |||
|         equal(tr.txt, "Test value abc"); | ||||
| 
 | ||||
|     }], | ||||
|     ["Preset renders icon correctly", () => { | ||||
|     }] | ||||
|     ["Parse tag config", (() => { | ||||
|         const tag = FromJSON.Tag("key=value") as Tag; | ||||
|         equal(tag.key, "key"); | ||||
|         equal(tag.value, "value"); | ||||
| 
 | ||||
|         const and = FromJSON.Tag({"and": ["key=value", "x=y"]}) as And; | ||||
|         equal((and.and[0] as Tag).key, "key"); | ||||
|         equal((and.and[1] as Tag).value, "y"); | ||||
| 
 | ||||
|     })], | ||||
|     ["Parse translation map", (() => { | ||||
| 
 | ||||
|         const json: any = {"en": "English", "nl": "Nederlands"}; | ||||
|         const translation = Translations.WT(FromJSON.Translation(json)); | ||||
|         Locale.language.setData("en"); | ||||
|         equal(translation.txt, "English"); | ||||
|         Locale.language.setData("nl"); | ||||
|         equal(translation.txt, "Nederlands"); | ||||
|     })], | ||||
|     ["Parse tag rendering", (() => { | ||||
|         Locale.language.setData("nl"); | ||||
|         const tr = FromJSON.TagRendering({ | ||||
|             render: ({"en":"Name is {name}", "nl":"Ook een {name}"} as any), | ||||
|             question: "Wat is de naam van dit object?", | ||||
|             freeform: { | ||||
|                 key: "name", | ||||
|             }, | ||||
|             fixedInputField: { | ||||
|                 mappings: [ | ||||
|                     { | ||||
|                         if: "noname=yes", | ||||
|                         "then": "Has no name" | ||||
|                     } | ||||
|                 ] | ||||
|             }, | ||||
|             condition: "x=" | ||||
|         }); | ||||
| 
 | ||||
|         equal(true, tr.IsKnown({"noname": "yes"})); | ||||
|         equal(true, tr.IsKnown({"name": "ABC"})); | ||||
|         equal(false, tr.IsKnown({"foo": "bar"})); | ||||
|         equal("Has no name", tr.GetContent({"noname": "yes"})); | ||||
|         equal("Ook een xyz", tr.GetContent({"name": "xyz"})); | ||||
|         equal("Ook een {name}", tr.GetContent({"foo": "bar"})); | ||||
| 
 | ||||
|     })] | ||||
| ]); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue