Refactoring ui/builder and template builder to preserve source information for templates

This commit is contained in:
Panayot Cankov
2015-11-25 12:45:02 +02:00
parent 8bee3ed2d1
commit 5447b04e86
6 changed files with 454 additions and 329 deletions

View File

@@ -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>

View File

@@ -837,7 +837,7 @@ export function test_parse_template_property() {
TKUnit.assertEqual(button.text, "Click!", "Expected child Button to have text 'Click!'");
}
export function test_ParserError() {
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" +
@@ -856,3 +856,28 @@ export function test_ParserError() {
}
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");
}