Ejemplo n.º 1
0
        private void ComparePipData(string expected, string objectToSerialize, string quoteChar = "\'")
        {
            var result = Build().AddSpec("const obj = " + objectToSerialize + ";").EvaluateExpressionWithNoErrors("obj") as ObjectLiteral;

            Assert.True(result != null, "Expected to receive an ObjectLiteral from evaluation the data");

            var renderer = new PipFragmentRenderer(
                absPath => {
                var path     = absPath.ToString(PathTable, PathFormat.Script);
                var testRoot = TestRoot.Replace('\\', '/') + "/";
                if (path.StartsWith(testRoot, StringComparison.OrdinalIgnoreCase))
                {
                    return("##" + path.Substring(testRoot.Length) + "##");
                }
                return("##" + path + "##");
            },
                StringTable,
                x => "@@" + x + "@@");
            var pipData = AmbientJson.CreatePipData(StringTable, result, quoteChar, new PipDataBuilder(StringTable));

            var canonicalPipData  = pipData.ToString(renderer).Replace("\r\n", "\n").Replace("/", "\\\\");
            var canonicalExpected = expected.Replace("\r\n", "\n").Replace("/", "\\\\");

            Assert.Equal(canonicalExpected, canonicalPipData);
        }
Ejemplo n.º 2
0
        public void TestOverrideWithLeft(string leftObject, string expectedResult)
        {
            var result = EvaluateSpec(
                $@"
const o1 = {leftObject};
export const result = o1.toString();
",
                new[] { "result" });

            result.ExpectNoError();

            var actualResult = (string)result.Values[0];

            if (expectedResult.Contains("b:"))
            {
                var testFolder = (TestRoot.Replace("\\", "/")).ToLowerInvariant();
                actualResult = actualResult.ToLowerInvariant().Replace(testFolder, "b:");
            }

            AssertEqualDiscardingTrivia(expectedResult, actualResult);
        }
Ejemplo n.º 3
0
        public void TestReadThenWrte(string xml)
        {
            var spec   = @"
namespace M {
    const result = _PreludeAmbientHack_Xml.read(f`in.xml`);

}";
            var result = Build()
                         .AddFile("in.xml", xml)
                         .AddSpec(spec)
                         .EvaluateExpressionWithNoErrors("M.result");

            var objectLiteral = result as ObjectLiteral;

            Assert.NotNull(objectLiteral);

            var renderer = new PipFragmentRenderer(
                absPath => {
                var path     = absPath.ToString(PathTable, PathFormat.Script);
                var testRoot = TestRoot.Replace('\\', '/') + "/TestSln/src/";
                if (path.StartsWith(testRoot, StringComparison.OrdinalIgnoreCase))
                {
                    return("##" + path.Substring(testRoot.Length) + "##");
                }
                return("##" + path + "##");
            },
                StringTable,
                x => "@@" + x + "@@");
            var pipData = AmbientXml.CreatePipData(StringTable, objectLiteral, new PipDataBuilder(StringTable));

            var canonicalPipData  = pipData.ToString(renderer).Replace("\r\n", "\n").Replace("/", "\\\\");
            var canonicalExpected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + xml.Replace("\r\n", "\n").Replace("/", "\\\\");

            // skip read-write test if xml contains DOCTYPE because our writer doesn't generate <!DOCTYPE>
            if (!xml.ToUpperInvariant().Contains("DOCTYPE"))
            {
                Assert.Equal(canonicalExpected, canonicalPipData);
            }
        }