mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-30 23:23:02 +00:00 
			
		
		
		
	* Add tests for [is[variable]] and "faked" variables See GH #6303 * Make is[variable] and variables[] operators resilient to fake widgets Co-authored-by: jeremy@jermolene.com <jeremy@jermolene.com>
This commit is contained in:
		| @@ -19,13 +19,13 @@ exports.variable = function(source,prefix,options) { | ||||
| 	var results = []; | ||||
| 	if(prefix === "!") { | ||||
| 		source(function(tiddler,title) { | ||||
| 			if(!(title in options.widget.variables)) { | ||||
| 			if(options.widget.getVariable(title) === undefined) { | ||||
| 				results.push(title); | ||||
| 			} | ||||
| 		}); | ||||
| 	} else { | ||||
| 		source(function(tiddler,title) { | ||||
| 			if(title in options.widget.variables) { | ||||
| 			if(options.widget.getVariable(title) !== undefined) { | ||||
| 				results.push(title); | ||||
| 			} | ||||
| 		}); | ||||
|   | ||||
| @@ -16,10 +16,16 @@ Filter operator for returning the names of the active variables | ||||
| Export our filter function | ||||
| */ | ||||
| exports.variables = function(source,operator,options) { | ||||
| 	var names = []; | ||||
| 	for(var variable in options.widget.variables) { | ||||
| 	var names = [], | ||||
| 		widget = options.widget; | ||||
| 	while(widget && !widget.hasOwnProperty("variables")) { | ||||
| 		widget = widget.parentWidget; | ||||
| 	} | ||||
| 	if(widget && widget.variables) { | ||||
| 		for(var variable in widget.variables) { | ||||
| 			names.push(variable); | ||||
| 		} | ||||
| 	} | ||||
| 	return names.sort(); | ||||
| }; | ||||
|  | ||||
|   | ||||
							
								
								
									
										27
									
								
								editions/test/tiddlers/tests/data/filters/fake-variables.tid
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								editions/test/tiddlers/tests/data/filters/fake-variables.tid
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| title: Filters/FakeVariables | ||||
| description: Test for https://github.com/Jermolene/TiddlyWiki5/issues/6303 | ||||
| type: text/vnd.tiddlywiki-multiple | ||||
| tags: [[$:/tags/wiki-test-spec]] | ||||
|  | ||||
| title: Output | ||||
|  | ||||
| \whitespace trim | ||||
| <$list variable="var" filter="[[existing variable should have output]] :filter[[..currentTiddler]is[variable]]"> | ||||
| <p><<var>></p> | ||||
| </$list> | ||||
|  | ||||
| <$list variable="var" filter="[[non-existing variable should not have output]] :filter[[nonExistingVariable]is[variable]]"> | ||||
| <p><<var>></p> | ||||
| </$list> | ||||
|  | ||||
| <$list variable="var" filter="[[existing variable negated should not have output]] :filter[[..currentTiddler]!is[variable]]"> | ||||
| <p><<var>></p> | ||||
| </$list> | ||||
|  | ||||
| <$list variable="var" filter="[[non-existing variable negated should have output]] :filter[[nonExistingVariable]!is[variable]]"> | ||||
| <p><<var>></p> | ||||
| </$list> | ||||
| + | ||||
| title: ExpectedResult | ||||
|  | ||||
| <p><p>existing variable should have output</p></p><p></p><p></p><p><p>non-existing variable negated should have output</p></p> | ||||
		Reference in New Issue
	
	Block a user
	 Rob Hoelz
					Rob Hoelz