public void ParseCharacterList() { Datum characterList = new ListDatum ( new Datum[] { new CharDatum('a'), new CharDatum('\uFEFF'), new CharDatum('\n'), } .ToImmutableList() ); var result = CharParserContext.TryParse ( Parser.ParseConvert ( parseDatum, d => DatumEqualityComparer.Instance.Equals(d, characterList), null ), "(#\\a #\\xFEFF #\\newline)" ); Assert.AreEqual("{ success, pos = 0, len = 23, value = True }", formatBoolResult(result)); }
public void ParseComplexDictionary() { Datum complexDictionary = DictionaryDatum.FromEnumerable ( new Tuple <Datum, Datum>[] { new Tuple <Datum, Datum>(BooleanDatum.True, BooleanDatum.False), new Tuple <Datum, Datum>(NullDatum.Value, new IntDatum(1000)), new Tuple <Datum, Datum>(new ListDatum(new Datum[] { BooleanDatum.True, new RationalDatum(BigRational.OneHalf) }.ToImmutableList()), new SymbolDatum("blah")), } ); var result = CharParserContext.TryParse ( Parser.ParseConvert ( parseDatum, d => DatumEqualityComparer.Instance.Equals(d, complexDictionary), null ), " { #t => #f, #nil => 1000, (#t 1/2) => blah }" ); Assert.AreEqual("{ success, pos = 0, len = 45, value = True }", formatBoolResult(result)); }
public void ParseMutableBoxes() { var d1 = CharParserContext.TryParse ( Parser.ParseDatumWithBoxes, "#b[1]=(1 2 #b[2]=(3 4 #b[3]=(5 6 #b[1])))" ); // unfortunately, you have to use the debugger to see if this is parsed correctly. if (d1 is ParseSuccess <Datum> ) { byte[] b0 = ((ParseSuccess <Datum>)d1).Value.SerializeToBytes(); Datum d3 = b0.DeserializeToDatum(); byte[] b1 = d3.SerializeToBytes(); Assert.IsTrue(b0.Length == b1.Length && Enumerable.Range(0, b0.Length).All(i => b0[i] == b1[i])); } else { Assert.Fail("Parsing failed"); } }
public void ParseComplexList() { Datum complexList = new ListDatum ( new Datum[] { BooleanDatum.True, NullDatum.Value, new FloatDatum(-3.75), new ListDatum ( new Datum[] { BooleanDatum.True, BooleanDatum.False, } .ToImmutableList() ) } .ToImmutableList() ); var result = CharParserContext.TryParse ( Parser.ParseConvert ( parseDatum, d => DatumEqualityComparer.Instance.Equals(d, complexList), null ), " ( #t #nil -3.75\r\n (#t #f) )" ); Assert.AreEqual("{ success, pos = 0, len = 28, value = True }", formatBoolResult(result)); }
public void ParseDouble() { var result = CharParserContext.TryParse ( Parser.ParseDouble, "6.125" ); Assert.AreEqual("{ success, pos = 0, len = 5, value = 6.125 }", formatDoubleResult(result)); }
public void ParseNotBigIntegerButFloat() { var result = CharParserContext.TryParse ( Parser.ParseBigInteger, "1.5" ); Assert.AreEqual("{ failure, { pos = 0, message = \"Failed to parse integer\" } }", formatBigIntegerResult(result)); }
public void ParseBigInteger() { var result = CharParserContext.TryParse ( Parser.ParseBigInteger, "-2359862495629582635" ); Assert.AreEqual("{ success, pos = 0, len = 20, value = -2359862495629582635 }", formatBigIntegerResult(result)); }
public void ParseDoubleWithExponent() { var result = CharParserContext.TryParse ( Parser.ParseDouble, "1.5e+24" ); Assert.AreEqual("{ success, pos = 0, len = 7, value = 1.5E+24 }", formatDoubleResult(result)); }
public void ParseNotDoubleButInteger() { var result = CharParserContext.TryParse ( Parser.ParseDouble, "10000000" ); Assert.AreEqual("{ failure, { pos = 0, message = \"Failed to parse float (int part)\" } }", formatDoubleResult(result)); }
public void ParseRational() { var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseBigRational, r => (r == BigRational.OneHalf), "failed to test big rational" ), "1/2" ); Assert.AreEqual("{ success, pos = 0, len = 3, value = True }", formatBoolResult(result)); }
public void ParseNamedCharInvalid() { var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseNamedChar, r => true, "failed to test invalid named character" ), "#\\wrong" ); Assert.AreEqual("{ failure, { pos = 0, message = \"Failed to parse named character\" } }", formatBoolResult(result)); }
public void ParseSpaceTrue() { var result = CharParserContext.TryParse ( Parser.ParseConvert ( parseDatum, d => DatumEqualityComparer.Instance.Equals(d, BooleanDatum.True), null ), " #t" ); Assert.AreEqual("{ success, pos = 0, len = 3, value = True }", formatBoolResult(result)); }
public void ParseGuid() { var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseGuid, g => g == new Guid("{01234567-89ab-cdef-0123-456789ABCDEF}"), null ), "#g{01234567-89ab-cdef-0123-456789ABCDEF}" ); Assert.AreEqual("{ success, pos = 0, len = 40, value = True }", formatBoolResult(result)); }
public void ParseLiteralChar() { var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseLiteralChar, r => (r == '$'), "failed to test literal character" ), "#\\$" ); Assert.AreEqual("{ success, pos = 0, len = 3, value = True }", formatBoolResult(result)); }
public void ParseQuotedSymbolWithEscapedBar() { var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseQuotedSymbol, s => string.Compare(s, "|", StringComparison.InvariantCulture) == 0, "failed to test string" ), "|\\||" ); Assert.AreEqual("{ success, pos = 0, len = 4, value = True }", formatBoolResult(result)); }
public void ParseHexChar() { var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseHexChar, r => (r == 'a'), "failed to test hex character" ), "#\\x61" ); Assert.AreEqual("{ success, pos = 0, len = 5, value = True }", formatBoolResult(result)); }
public void ParseStringWithNewlineEscape() { var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseString, s => string.Compare(s, "abcd", StringComparison.InvariantCulture) == 0, "failed to test string" ), "\"ab\\\r\ncd\"" ); Assert.AreEqual("{ success, pos = 0, len = 9, value = True }", formatBoolResult(result)); }
public void ParseQuasiQuoteUnquote() { Datum d = new ListDatum ( ImmutableList <Datum> .Empty .Add(new SymbolDatum("quasiquote")) .Add ( new ListDatum ( ImmutableList <Datum> .Empty .Add(new SymbolDatum("a")) .Add(new SymbolDatum("b")) .Add ( new ListDatum ( ImmutableList <Datum> .Empty .Add(new SymbolDatum("unquote")) .Add(new SymbolDatum("x")) ) ) .Add ( new ListDatum ( ImmutableList <Datum> .Empty .Add(new SymbolDatum("unquote-splicing")) .Add(new SymbolDatum("y")) ) ) ) ) ); var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseDatum, a => DatumEqualityComparer.Instance.Equals(a, d), null ), " `(a b ,x ,@y)" ); Assert.AreEqual("{ success, pos = 0, len = 14, value = True }", formatBoolResult(result)); }
public void ParseSet() { Datum set = SetDatum.Empty.Add(new SymbolDatum("a")).Add(new SymbolDatum("b")).Add(new IntDatum(1000)); var result = CharParserContext.TryParse ( Parser.ParseConvert ( parseDatum, d => DatumEqualityComparer.Instance.Equals(d, set), null ), "#s{ a b 1000 }" ); Assert.AreEqual("{ success, pos = 0, len = 14, value = True }", formatBoolResult(result)); }
public string VisitSymbol(SymbolDatum d) { if (d.IsInterned) { var result = CharParserContext.TryParse(Parser.ParseUnquotedSymbolThenEof, d.Name); if (result is ParseSuccess <string> ) { return(d.Name); } else { return(d.Name.SymbolQuoted()); } } else { return("g$" + d.ID); } }
public void ParseByteArray() { byte[] b = new byte[] { 0xFE, 0x12, 0x3A, 0x4B, 0x79, 0x18, 0x02, 0xA3 }; var result = CharParserContext.TryParse ( Parser.ParseConvert ( Parser.ParseByteArray, a => a.Length == 8 && Enumerable.Range(0, 8).All(i => a[i] == b[i]), null ), "#y(FE12 3A4B [1879] 02A3)" ); Assert.AreEqual("{ success, pos = 0, len = 25, value = True }", formatBoolResult(result)); }
public void ParseOptRepWithTwo() { Assert.AreEqual("{ success, pos = 0, len = 6, value = [ \"abc\", \"abc\" ] }", toString(CharParserContext.TryParse(parserOptRep, "abcabcde"))); }
public void ParseExact() { Assert.AreEqual("{ success, pos = 0, len = 3, value = \"Abc\" }", toString(CharParserContext.TryParse(parser, "Abc"))); }
public void ParseExactWithExtraInput() { Assert.AreEqual("{ success, pos = 0, len = 3, value = \"ABC\" }", toString(CharParserContext.TryParse(parser, "ABCD"))); }
public void ParseOptRepWithNone() { Assert.AreEqual("{ success, pos = 0, len = 0, value = [ ] }", toString(CharParserContext.TryParse(parserOptRep, "de"))); }
public void TestSpaceA() { Assert.AreEqual("{ success, pos = 0, len = 2, value = \"A\" }", toString2(CharParserContext.TryParse(a, " A"))); }
public void TestNoSpace() { Assert.AreEqual("{ success, pos = 0, len = 0, value = null }", toString(CharParserContext.TryParse(ws, "a"))); }
public void ParseExactWithShortInput() { Assert.AreEqual("{ failure, { pos = 0, message = \"Expected \\\"abc\\\", found EOF\" } }", toString(CharParserContext.TryParse(parser, "AB"))); }
public void TestSpaceB() { Assert.AreEqual("{ failure, { pos = 1, message = \"Expected \\\"a\\\"\" } }", toString2(CharParserContext.TryParse(a, " B"))); }
public void ParseRepWithOne() { Assert.AreEqual("{ success, pos = 0, len = 3, value = [ \"abc\" ] }", toString(CharParserContext.TryParse(parserRep, "abcde"))); }