本文整理汇总了TypeScript中tns-core-modules/file-system.File.fromPath方法的典型用法代码示例。如果您正苦于以下问题:TypeScript File.fromPath方法的具体用法?TypeScript File.fromPath怎么用?TypeScript File.fromPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tns-core-modules/file-system.File
的用法示例。
在下文中一共展示了File.fromPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export var test_XmlParser_IntegrationTest = function () {
var actualResult = "";
var xmlParser = new xmlModule.XmlParser(function (event: xmlModule.ParserEvent) {
if (event.eventType === xmlModule.ParserEventType.Text && event.data.trim() === "") {
// Ignore ignorable whitespace.
return;
}
actualResult += event.toString();
});
var file = fs.File.fromPath(fs.path.join(__dirname, "xml.xml"));
var xmlString = file.readTextSync();
xmlString = xmlString.replace(/(\r\n|\n|\r)/gm, "\n");
xmlParser.parse(xmlString);
var expectedResult: string;
file = fs.File.fromPath(fs.path.join(__dirname, "xml.expected"));
expectedResult = file.readTextSync();
var i;
var maxLength = Math.max(actualResult.length, expectedResult.length);
for (i = 0; i < maxLength; i++) {
var actualChar;
var actualCharCode;
if (i <= actualResult.length) {
actualChar = actualResult.charAt(i);
actualCharCode = actualResult.charCodeAt(i);
}
else {
actualChar = "undefined";
actualCharCode = "undefined";
}
var expectedChar;
var expectedCharCode;
if (i <= expectedResult.length) {
expectedChar = expectedResult.charAt(i);
expectedCharCode = expectedResult.charCodeAt(i);
}
else {
expectedChar = "undefined";
expectedCharCode = "undefined";
}
TKUnit.assert(actualCharCode === expectedCharCode, "At index " + i + ": Actual character is " + actualChar + "[" + actualCharCode + "]; Expected character is: " + expectedChar + "[" + expectedCharCode + "]");
}
};
示例2: test_MultiParserTemplate
export function test_MultiParserTemplate() {
const file = fs.File.fromPath(fs.path.join(__dirname, "itemTemplates.xml"));
const xml = file.readTextSync();
const view: any = builder.parse(xml);
TKUnit.assertNotNull(view.items)
TKUnit.assertEqual(view.items.length, 1);
}
示例3: function
export var test_UTF8_BOM_is_not_returned = function () {
var actualResult: string;
var path = fs.path.join(__dirname, "xml.expected");
if (!fs.File.exists(path)) {
TKUnit.assert(false, "Could not read file utf8.txt");
return;
}
var file = fs.File.fromPath(path);
var onError = function (error) {
TKUnit.assert(false, "Could not read file utf8.txt");
}
var text = file.readTextSync(onError);
if (text) {
var actualCharCode = text.charCodeAt(0);
var expectedCharCode = "{".charCodeAt(0);
TKUnit.assert(actualCharCode === expectedCharCode, "Actual character code: " + actualCharCode + "; Expected character code: " + expectedCharCode);
}
};
示例4: fileFromPath
public fileFromPath(path: string): File {
return File.fromPath(path);
}