Esempio n. 1
0
    def test_unary(self):
        compiler = Compiler()

        result = compiler.compile("+1")
        self.assertIsInstance(result, UnaryOperator)
        self.assertEqual(result.operator, "+")
        self.assertEqual(result.operand, 1)
    def test_unary(self):
        compiler = Compiler()

        result = compiler.compile("+1")
        self.assertIsInstance(result, UnaryOperator)
        self.assertEqual(result.operator, "+")
        self.assertEqual(result.operand, 1)
Esempio n. 3
0
    def test_binary(self):
        compiler = Compiler()

        result = compiler.compile("101 + 202")
        self.assertIsInstance(result, BinaryOperator)
        self.assertEqual(result.operator, "+")
        self.assertEqual(result.left, 101)
        self.assertEqual(result.right, 202)
Esempio n. 4
0
    def test_strings(self):
        compiler = Compiler()

        result = compiler.compile("''")
        self.assertEqual(result, "")

        result = compiler.compile("'a \\' quote'")
        self.assertEqual(result, "a ' quote")
Esempio n. 5
0
    def test_strings(self):
        compiler = Compiler()

        result = compiler.compile("''")
        self.assertEqual(result, "")

        result = compiler.compile("'a \\' quote'")
        self.assertEqual(result, "a ' quote")
    def test_binary(self):
        compiler = Compiler()

        result = compiler.compile("101 + 202")
        self.assertIsInstance(result, BinaryOperator)
        self.assertEqual(result.operator, "+")
        self.assertEqual(result.left, 101)
        self.assertEqual(result.right, 202)
Esempio n. 7
0
    def test_variable(self):
        compiler = Compiler()
        result = compiler.compile("foo")
        self.assertIsInstance(result, Variable)
        self.assertEqual(result.name, "foo")
        self.assertEqual(result.reference, ["foo"])

        result = compiler.compile("foo.bar.baz")
        self.assertIsInstance(result, Variable)
        self.assertEqual(result.name, "foo.bar.baz")
        self.assertEqual(result.reference, ["foo", "bar", "baz"])
Esempio n. 8
0
    def test_variable(self):
        compiler = Compiler()
        result = compiler.compile("foo")
        self.assertIsInstance(result, Variable)
        self.assertEqual(result.name, "foo")
        self.assertEqual(result.reference, ["foo"])

        result = compiler.compile("foo.bar.baz")
        self.assertIsInstance(result, Variable)
        self.assertEqual(result.name, "foo.bar.baz")
        self.assertEqual(result.reference, ["foo", "bar", "baz"])
Esempio n. 9
0
    def test_basic(self):
        compiler = Compiler()
        result = compiler.compile("1")
        self.assertEqual(result, 1)
        self.assertIsInstance(result, int)

        result = compiler.compile("1.2")
        self.assertEqual(result, 1.2)
        self.assertIsInstance(result, float)

        result = compiler.compile("'a string'")
        self.assertEqual(result, "a string")
        self.assertIsInstance(result, str)
Esempio n. 10
0
    def test_basic(self):
        compiler = Compiler()
        result = compiler.compile("1")
        self.assertEqual(result, 1)
        self.assertIsInstance(result, int)

        result = compiler.compile("1.2")
        self.assertEqual(result, 1.2)
        self.assertIsInstance(result, float)

        result = compiler.compile("'a string'")
        self.assertEqual(result, "a string")
        self.assertIsInstance(result, str)
Esempio n. 11
0
    def test_operator(self):
        compiler = Compiler()

        result = compiler.compile("+1")
        self.assertIsInstance(result, UnaryOperator)
        self.assertEqual(result.operator, "+")
        self.assertEqual(result.operand, 1)

        result = compiler.compile("1 and 2")
        self.assertIsInstance(result, BinaryOperator)
        self.assertEqual(result.operator, "and")
        self.assertEqual(result.left, 1)
        self.assertEqual(result.right, 2)
Esempio n. 12
0
    def test_function(self):
        compiler = Compiler()

        result = compiler.compile("foo()")
        self.assertIsInstance(result, Function)
        self.assertEqual(result.name, "foo")
        self.assertEqual(result.reference, ["foo"])
        self.assertEqual(result.args, [])

        result = compiler.compile("foo.bar.baz()")
        self.assertIsInstance(result, Function)
        self.assertEqual(result.name, "foo.bar.baz")
        self.assertEqual(result.reference, ["foo", "bar", "baz"])
        self.assertEqual(result.args, [])

        result = compiler.compile("foo(10,20,30)")
        self.assertIsInstance(result, Function)
        self.assertEqual(result.args, [10, 20, 30])
Esempio n. 13
0
    def test_function(self):
        compiler = Compiler()

        result = compiler.compile("foo()")
        self.assertIsInstance(result, Function)
        self.assertEqual(result.name, "foo")
        self.assertEqual(result.reference, ["foo"])
        self.assertEqual(result.args, [])

        result = compiler.compile("foo.bar.baz()")
        self.assertIsInstance(result, Function)
        self.assertEqual(result.name, "foo.bar.baz")
        self.assertEqual(result.reference, ["foo", "bar", "baz"])
        self.assertEqual(result.args, [])

        result = compiler.compile("foo(10,20,30)")
        self.assertIsInstance(result, Function)
        self.assertEqual(result.args, [10, 20, 30])