...
 
Commits (2)
......@@ -2,3 +2,6 @@ module namespace foobar2 = "pseudo://test-module2";
import module namespace foo = "pseudo://test-module" at "module.xq";
declare variable $foobar2:def := $foo:abc * 1000 ;
declare function foobar2:setglobal (){
$newglobal := "GLOABL"
};
\ No newline at end of file
newglobal := GLOABL
GLOABL
xx:GLOABL
newglobal := GLOABL
xxx := GLOABL
init
res := AAA
res := v1
res := v2
res:v1
res:v2
res:AAA
......
......@@ -416,10 +416,19 @@ tests/test.sh moduleFuncImport --module tests/module.xq -e '$foobar:abc'
tests/test.sh moduleFuncImport2 -e 'import module namespace rename = "pseudo://test-module" at "tests/module.xq"; ()' -e 'rename:test()'
tests/test.sh moduleFuncImport2 --module tests/module.xq -e 'foobar:test()'
tests/test.sh moduleFuncImport2 --module rename=tests/module.xq -e 'rename:test()'
tests/test.sh moduleFuncImport2 --module tests/module.xq -e 'import module namespace rename = "pseudo://test-module" at "tests/module.xq"; ()' -e 'rename:test()'
tests/test.sh moduleFuncImport2 --module xyz=tests/module.xq -e 'import module "pseudo://test-module"; ()' -e 'foobar:test()'
tests/test.sh moduleFuncImportRel --module tests/module2.xqm -e '$foobar2:def'
tests/test.sh moduleFuncImportRel -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; $rename:def'
tests/test.sh moduleFuncImportRel --module xyz=tests/module2.xqm -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; $rename:def'
tests/test.sh moduleFuncImportRel --extract-file tests/subdir/test.xq
tests/test.sh moduleFuncImportRel tests/subdir/test.xq
tests/test.sh moduleFuncImportGlobalMut --module tests/module2.xqm -e 'foobar2:setglobal()'
tests/test.sh moduleFuncImportGlobalMut -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; rename:setglobal()'
tests/test.sh moduleFuncImportGlobalMut2 --module tests/module2.xqm -e 'foobar2:setglobal(), "xx:" || $newglobal'
tests/test.sh moduleFuncImportGlobalMut2 -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; rename:setglobal(), "xx:" || $newglobal'
tests/test.sh moduleFuncImportGlobalMut3 --module tests/module2.xqm -e 'xxx := foobar2:setglobal()'
tests/test.sh moduleFuncImportGlobalMut3 -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; xxx := rename:setglobal()'
tests/test.sh varlogBC -e 'x:clear-log(),a:=1,a:=2,b:=3,c:=4,x:clear-log("a"), t:=x:get-log(), u:=("a","b","c")!(.,x:get-log(.))'
tests/test.sh varlogAC -e 'x:clear-log(),a:=1,a:=2,b:=3,c:=4,x:clear-log("b"), t:=x:get-log(), u:=("a","b","c")!(.,x:get-log(.))'
......@@ -540,6 +549,7 @@ tests/test.sh moreActions2 -e '"init"||get("res")' --template-action ac2 --temp
tests/test.sh moreActionsLocalPattern --template-action local --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActions -e '"init"||get("res")' --template-action ac1 --template-file tests/more.actions --xquery '"res:" || $res, for $i in ("ac2", "local", "ac1", "ac2") return ( x:call-action($i), "res:"||$res)' #variables set by call-action are reordered before the extract print, since the values of the extract are only known after the for has finished
echo
echo Results:
wc -l /tmp/xidel-tests-state-ok /tmp/xidel-tests-state-failed 2> /dev/null | grep tests | sed -Ee 's/([0-9]+).*-([^-]+)/\1 \2/'
......@@ -2558,6 +2558,7 @@ end;
procedure TExtraction.pageProcessed(unused: TMultipageTemplateReader; parser: THtmlTemplateParser);
begin
printExtractedVariables(parser, false);
THtmlTemplateParserBreaker(htmlparser).closeVariableLog;
end;
......@@ -2578,6 +2579,7 @@ function TExtraction.process(data: IData): TFollowToList;
var
value: IXQValue;
oldvarlogcount: Integer;
begin
//set flags when first processed
if isStdin(extract) then extract:=strReadFromStdin;
......@@ -2620,12 +2622,15 @@ begin
end;
end;
parent.loadDataForQuery(data, extractQueryCache);
THtmlTemplateParserBreaker(htmlparser).closeVariableLog;
if termContainsVariableDefinition(extractQueryCache.Term) then begin
THtmlTemplateParserBreaker(htmlparser).closeVariableLog;
parent.evaluateQuery(extractQueryCache, data, true);
printExtractedVariables(htmlparser, true);
end else begin
oldvarlogcount := htmlparser.variableChangeLog.count;
value := parent.evaluateQuery(extractQueryCache, data, true);
if oldvarlogcount <> htmlparser.variableChangeLog.count then
printExtractedVariables(htmlparser, true); //still print variables when some where set when we do not expect it, because termContainsVariableDefinition failed to find the assignment (e.g. through a function call)
writeBeginGroup;
printExtractedValue(value, false);
writeEndGroup;
......@@ -3516,6 +3521,8 @@ function loadModuleFromAtUrl(const at, base: string): IXQuery;
var d: IData;
ft: TFollowTo;
url, oldBaseUri: String;
visitor: TXQTerm_VisitorFindWeirdGlobalVariableDeclarations;
term: TXQTerm;
begin
url := strResolveURI(at, base);
try
......@@ -3529,6 +3536,16 @@ begin
xpathparser.StaticContext.baseURI := url;
result := xpathparser.parseXQuery3(d.rawData);
xpathparser.StaticContext.baseURI := oldBaseUri;
visitor := TXQTerm_VisitorFindWeirdGlobalVariableDeclarations.Create;
visitor.findNestedVariables := true;
visitor.listVars := true;
term := result.getTerm;
visitor.simpleTermVisit(@term, nil);
for i := 0 to high(visitor.vars) do with visitor.vars[i] do TXQueryEngineBreaker(xpathparser).addAWeirdGlobalVariable(namespace, value);
visitor.free;
result.getTerm;
end;
procedure importModule(pseudoSelf: tobject; sender: TXQueryEngine; context: TXQStaticContext; const namespace: string; const at: array of string);
......