本文整理匯總了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);
}