当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript File.fromPath方法代码示例

本文整理汇总了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 + "]");
    }
};
开发者ID:triniwiz,项目名称:NativeScript,代码行数:49,代码来源:xml-parser-tests.ts

示例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);
}
开发者ID:triniwiz,项目名称:NativeScript,代码行数:8,代码来源:xml-parser-tests.ts

示例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);
    }
};
开发者ID:NathanWalker,项目名称:NativeScript,代码行数:21,代码来源:file-system-access-tests.ts

示例4: fileFromPath

 public fileFromPath(path: string): File {
     return File.fromPath(path);
 }
开发者ID:NathanWalker,项目名称:nativescript-angular,代码行数:3,代码来源:ns-file-system.ts


注:本文中的tns-core-modules/file-system.File.fromPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。