def test_literal(self): """ Literals are parsed to literal terms. """ parse = self.getParser("literal") self.assertEqual(parse('"foo bar"'), TermLiteral('.String.', "foo bar")) self.assertEqual(parse("'x'"), TermLiteral('.char', character('x'))) self.assertEqual(parse("0xDECAFC0FFEEBAD"), TermLiteral('.int.', 0xDECAFC0FFEEBAD)) self.assertEqual(parse("0755"), TermLiteral('.int.', 0755)) self.assertEqual(parse("3.14159E17"), TermLiteral('.float64.', 3.14159E17)) self.assertEqual(parse("1e9"), TermLiteral('.float64.', 1e9)) self.assertEqual(parse("0"), TermLiteral(".int.", 0)) self.assertEqual(parse("7"), TermLiteral(".int", 7)) self.assertEqual(parse("-1"), TermLiteral(".int.", -1)) self.assertEqual(parse("-3.14"), TermLiteral('.float64.', -3.14)) self.assertEqual(parse("3_000"), TermLiteral('.int.', 3000)) self.assertEqual(parse("0.91"), TermLiteral('float64.', 0.91)) self.assertEqual(parse("3e-2"), TermLiteral('.float64.', 3e-2)) self.assertEqual(parse("'\\n'"), TermLiteral('.char.', character("\n"))) self.assertEqual(parse('"foo\\nbar"'), TermLiteral('.String.', "foo\nbar")) self.assertEqual(parse("'\\u0061'"), TermLiteral('.char.', character("a"))) self.assertEqual(parse('"z\141p"'), TermLiteral('.String.', "zap")) self.assertEqual(parse('"x\41"'), TermLiteral('.String.', "x!")) self.assertEqual(parse('"foo\\\nbar"'), TermLiteral('.String.', "foobar"))
def test_literal(self): """ Literals are parsed to literal terms. """ parse = self.getParser("literal") self.assertEqual(parse('"foo bar"'), Term(Tag('.String.'), "foo bar", None)) self.assertEqual(parse("'x'"), Term(Tag('.char.'), 'x', None)) self.assertEqual(parse("0xDECAFC0FFEEBAD"), Term(Tag('.int.'), 0xDECAFC0FFEEBAD, None)) self.assertEqual(parse("0755"), Term(Tag('.int.'), 0755, None)) self.assertEqual(parse("3.14159E17"), Term(Tag('.float64.'), 3.14159E17, None)) self.assertEqual(parse("1e9"), Term(Tag('.float64.'), 1e9, None)) self.assertEqual(parse("0"), Term(Tag(".int."), 0, None)) self.assertEqual(parse("7"), Term(Tag(".int."), 7, None)) self.assertEqual(parse("-1"), Term(Tag(".int."), -1, None)) self.assertEqual(parse("-3.14"), Term(Tag('.float64.'), -3.14, None)) self.assertEqual(parse("3_000"), Term(Tag('.int.'), 3000, None)) self.assertEqual(parse("0.91"), Term(Tag('.float64.'), 0.91, None)) self.assertEqual(parse("3e-2"), Term(Tag('.float64.'), 3e-2, None)) self.assertEqual(parse("'\\n'"), Term(Tag('.char.'), character("\n"), None)) self.assertEqual(parse('"foo\\nbar"'), Term(Tag('.String.'), "foo\nbar", None)) self.assertEqual(parse("'\\u0061'"), Term(Tag('.char.'), character("a"), None)) self.assertEqual(parse('"z\141p"'), Term(Tag('.String.'), "zap", None)) self.assertEqual(parse('"x\41"'), Term(Tag('.String.'), "x!", None)) self.assertEqual(parse('"foo\\\nbar"'), Term(Tag('.String.'), "foobar", None))
def test_literal(self): """ Literals are parsed to literal terms. """ parse = self.getParser("literal") self.assertEqual(parse('"foo bar"'), TermLiteral('.String.', "foo bar")) self.assertEqual(parse("'x'"), TermLiteral('.char', character('x'))) self.assertEqual(parse("0xDECAFC0FFEEBAD"), TermLiteral('.int.', 0xDECAFC0FFEEBAD)) self.assertEqual(parse("0755"), TermLiteral('.int.', 0o755)) self.assertEqual(parse("3.14159E17"), TermLiteral('.float64.', 3.14159E17)) self.assertEqual(parse("1e9"), TermLiteral('.float64.', 1e9)) self.assertEqual(parse("0"), TermLiteral(".int.", 0)) self.assertEqual(parse("7"), TermLiteral(".int", 7)) self.assertEqual(parse("-1"), TermLiteral(".int.", -1)) self.assertEqual(parse("-3.14"), TermLiteral('.float64.', -3.14)) self.assertEqual(parse("3_000"), TermLiteral('.int.', 3000)) self.assertEqual(parse("0.91"), TermLiteral('float64.', 0.91)) self.assertEqual(parse("3e-2"), TermLiteral('.float64.', 3e-2)) self.assertEqual(parse("'\\n'"), TermLiteral('.char.', character("\n"))) self.assertEqual(parse('"foo\\nbar"'), TermLiteral('.String.', "foo\nbar")) self.assertEqual(parse("'\\u0061'"), TermLiteral('.char.', character("a"))) self.assertEqual(parse('"z\141p"'), TermLiteral('.String.', "zap")) self.assertEqual(parse('"x\41"'), TermLiteral('.String.', "x!")) self.assertEqual(parse('"foo\\\nbar"'), TermLiteral('.String.', "foobar"))
def test_coerce(self): self.assertEqual( coerceToTerm({ 3: 4, "a": character('x'), (2, 3): [4, 5] }), parseTerm('{"a": \'x\', 3: 4, [2, 3]: [4, 5]}'))
def test_literal(self): """ Literals are parsed to literal terms. """ parse = self.getParser("literal") self.assertEqual(parse('"foo bar"'), Term(Tag('.String.'), "foo bar", None, None)) self.assertEqual(parse("'x'"), Term(Tag('.char.'), 'x', None, None)) self.assertEqual(parse("0xDECAFC0FFEEBAD"), Term(Tag('.int.'), 0xDECAFC0FFEEBAD, None, None)) self.assertEqual(parse("0755"), Term(Tag('.int.'), 0o755, None, None)) self.assertEqual(parse("3.14159E17"), Term(Tag('.float64.'), 3.14159E17, None, None)) self.assertEqual(parse("1e9"), Term(Tag('.float64.'), 1e9, None, None)) self.assertEqual(parse("0"), Term(Tag(".int."), 0, None, None)) self.assertEqual(parse("7"), Term(Tag(".int."), 7, None, None)) self.assertEqual(parse("-1"), Term(Tag(".int."), -1, None, None)) self.assertEqual(parse("-3.14"), Term(Tag('.float64.'), -3.14, None, None)) self.assertEqual(parse("3_000"), Term(Tag('.int.'), 3000, None, None)) self.assertEqual(parse("0.91"), Term(Tag('.float64.'), 0.91, None, None)) self.assertEqual(parse("3e-2"), Term(Tag('.float64.'), 3e-2, None, None)) self.assertEqual(parse("'\\n'"), Term(Tag('.char.'), character("\n"), None, None)) self.assertEqual(parse('"foo\\nbar"'), Term(Tag('.String.'), "foo\nbar", None, None)) self.assertEqual(parse("'\\u0061'"), Term(Tag('.char.'), character("a"), None, None)) self.assertEqual(parse('"z\141p"'), Term(Tag('.String.'), "zap", None, None)) self.assertEqual(parse('"x\41"'), Term(Tag('.String.'), "x!", None, None)) self.assertEqual(parse('"foo\\\nbar"'), Term(Tag('.String.'), "foobar", None, None))
def test_coerce(self): self.assertEqual( coerceToTerm({3: 4, "a": character('x'), (2, 3): [4, 5]}), parseTerm('{"a": \'x\', 3: 4, [2, 3]: [4, 5]}'))