mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #1125 from NativeScript/cankov/xml-source-tracing
Cankov/xml source tracing
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
|
||||
xmlns:tc="xml-declaration/template-builder-tests/template-view">
|
||||
<tc:TemplateView id="template-view">
|
||||
<tc:TemplateView.template>
|
||||
<StackLayout>
|
||||
<!--
|
||||
At first I was going to put "MenuItem",
|
||||
as per https://github.com/NativeScript/NativeScript/issues/501,
|
||||
but then again we may re-introduce "MenuItem" in future and blow this test up.
|
||||
So here is something unique that has better chance not to appear.
|
||||
This comment also offsets error's row and column numbers so if you edit,
|
||||
please do so beyond the unicorn.
|
||||
-->
|
||||
<Unicorn backgroundColor="pink" />
|
||||
<Label text="Modal Page" />
|
||||
</StackLayout>
|
||||
</tc:TemplateView.template>
|
||||
</tc:TemplateView>
|
||||
</Page>
|
||||
14
apps/tests/xml-declaration/errors/non-existing-element.xml
Normal file
14
apps/tests/xml-declaration/errors/non-existing-element.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<Page shownModally="onShownModally">
|
||||
<StackLayout>
|
||||
<!--
|
||||
At first I was going to put "MenuItem",
|
||||
as per https://github.com/NativeScript/NativeScript/issues/501,
|
||||
but then again we may re-introduce "MenuItem" in future and blow this test up.
|
||||
So here is something unique that has better chance not to appear.
|
||||
This comment also offsets error's row and column numbers so if you edit,
|
||||
please do so beyond the unicorn.
|
||||
-->
|
||||
<Unicorn backgroundColor="pink" />
|
||||
<Label text="Modal Page" />
|
||||
</StackLayout>
|
||||
</Page>
|
||||
@@ -835,4 +835,49 @@ export function test_parse_template_property() {
|
||||
var button = <Button>templateView.getChildAt(0);
|
||||
TKUnit.assert(button, "Expected the TemplateView's template to create a button child.");
|
||||
TKUnit.assertEqual(button.text, "Click!", "Expected child Button to have text 'Click!'");
|
||||
}
|
||||
|
||||
export function test_NonExistingElementError() {
|
||||
var basePath = "xml-declaration/";
|
||||
var expectedErrorStart =
|
||||
"Building UI from XML. @file:///app/" + basePath + "errors/non-existing-element.xml:11:5\n" +
|
||||
" ↳Module 'ui/unicorn' not found for element 'Unicorn'.\n";
|
||||
if (global.android) {
|
||||
expectedErrorStart += " ↳Module \"ui/unicorn\" not found";
|
||||
} else {
|
||||
expectedErrorStart += " ↳Failed to find module 'ui/unicorn'";
|
||||
}
|
||||
|
||||
var message;
|
||||
try {
|
||||
builder.load(__dirname + "/errors/non-existing-element.xml");
|
||||
} catch(e) {
|
||||
message = e.message;
|
||||
}
|
||||
TKUnit.assertEqual(message.substr(0, expectedErrorStart.length), expectedErrorStart, "Expected load to throw, and the message to start with specific string");
|
||||
}
|
||||
|
||||
export function test_NonExistingElementInTemplateError() {
|
||||
var basePath = "xml-declaration/";
|
||||
var expectedErrorStart =
|
||||
"Building UI from XML. @file:///app/" + basePath + "errors/non-existing-element-in-template.xml:14:17\n" +
|
||||
" ↳Module 'ui/unicorn' not found for element 'Unicorn'.\n";
|
||||
if (global.android) {
|
||||
expectedErrorStart += " ↳Module \"ui/unicorn\" not found";
|
||||
} else {
|
||||
expectedErrorStart += " ↳Failed to find module 'ui/unicorn'";
|
||||
}
|
||||
|
||||
var message;
|
||||
var page = builder.load(__dirname + "/errors/non-existing-element-in-template.xml");
|
||||
TKUnit.assert(view, "Expected the xml to generate a page");
|
||||
var templateView = <TemplateView>page.getViewById("template-view");
|
||||
TKUnit.assert(templateView, "Expected the page to have a TemplateView with 'temaplte-view' id.");
|
||||
|
||||
try {
|
||||
templateView.parseTemplate();
|
||||
} catch(e) {
|
||||
message = e.message;
|
||||
}
|
||||
TKUnit.assertEqual(message.substr(0, expectedErrorStart.length), expectedErrorStart, "Expected load to throw, and the message to start with specific string");
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
{"eventType":"StartElement","elementName":"DocumentElement","attributes":{"param":"value"}}{"eventType":"StartElement","elementName":"First.Element","attributes":{"some.attr":"some.value"}}{"eventType":"Text","data":"\n ¶ Some Text ®\n "}{"eventType":"EndElement","elementName":"First.Element"}{"eventType":"StartElement","elementName":"SecondElement","attributes":{"param2":"something"}}{"eventType":"Text","data":"\n Pre-Text "}{"eventType":"StartElement","elementName":"Inline"}{"eventType":"Text","data":"Inlined text"}{"eventType":"EndElement","elementName":"Inline"}{"eventType":"Text","data":" Post-text.\n "}{"eventType":"EndElement","elementName":"SecondElement"}{"eventType":"StartElement","elementName":"entities"}{"eventType":"Text","data":"Xml tags begin with \"<\" and end with \">\" Ampersand is & and apostrophe is '"}{"eventType":"EndElement","elementName":"entities"}{"eventType":"StartElement","elementName":"script"}{"eventType":"CDATA","data":"\nfunction sum(a,b)\n{\n return a+b;\n}\n"}{"eventType":"EndElement","elementName":"script"}{"eventType":"Comment","data":"\n Hello,\n I am a multi-line XML comment.\n"}{"eventType":"EndElement","elementName":"DocumentElement"}
|
||||
{"eventType":"StartElement","position":{"line":2,"column":1},"elementName":"DocumentElement","attributes":{"param":"value"}}{"eventType":"StartElement","position":{"line":3,"column":3},"elementName":"First.Element","attributes":{"some.attr":"some.value"}}{"eventType":"Text","position":{"line":3,"column":41},"data":"\n ¶ Some Text ®\n "}{"eventType":"EndElement","position":{"line":5,"column":3},"elementName":"First.Element"}{"eventType":"StartElement","position":{"line":7,"column":3},"elementName":"SecondElement","attributes":{"param2":"something"}}{"eventType":"Text","position":{"line":7,"column":37},"data":"\n Pre-Text "}{"eventType":"StartElement","position":{"line":8,"column":14},"elementName":"Inline"}{"eventType":"Text","position":{"line":8,"column":22},"data":"Inlined text"}{"eventType":"EndElement","position":{"line":8,"column":34},"elementName":"Inline"}{"eventType":"Text","position":{"line":8,"column":43},"data":" Post-text.\n "}{"eventType":"EndElement","position":{"line":9,"column":3},"elementName":"SecondElement"}{"eventType":"StartElement","position":{"line":10,"column":3},"elementName":"entities"}{"eventType":"Text","position":{"line":10,"column":13},"data":"Xml tags begin with \"<\" and end with \">\" Ampersand is & and apostrophe is '"}{"eventType":"EndElement","position":{"line":10,"column":123},"elementName":"entities"}{"eventType":"StartElement","position":{"line":11,"column":3},"elementName":"script"}{"eventType":"CDATA","position":{"line":12,"column":5},"data":"\nfunction sum(a,b)\n{\n return a+b;\n}\n"}{"eventType":"EndElement","position":{"line":18,"column":3},"elementName":"script"}{"eventType":"Comment","position":{"line":19,"column":3},"data":"\n Hello,\n I am a multi-line XML comment.\n"}{"eventType":"EndElement","position":{"line":23,"column":1},"elementName":"DocumentElement"}
|
||||
Reference in New Issue
Block a user