Пример #1
0
        public void parsesConstructor2AttributesComma()
        {
            String                statement = "Company(id=1, name=\"IBM\")";
            OTestParser           parser    = new OTestParser(statement);
            ConstructorExpression c         = parser.parse_constructor_expression();

            Assert.IsNotNull(c);
            ArgumentList l = c.getArguments();

            Assert.IsNotNull(l);
            Assert.AreEqual(2, l.Count);
            Argument a = l[0];

            Assert.IsNotNull(a);
            Assert.AreEqual("id", a.GetName());
            IExpression e = a.getExpression();

            Assert.IsNotNull(e);
            Assert.IsTrue(e is IntegerLiteral);
            a = l[1];
            Assert.IsNotNull(a);
            Assert.AreEqual("name", a.GetName());
            e = a.getExpression();
            Assert.IsNotNull(e);
            Assert.IsTrue(e is TextLiteral);
        }
Пример #2
0
        public void parsesInstanceExpression()
        {
            String      statement = "prefix ";
            OTestParser parser    = new OTestParser(statement);
            IExpression exp       = parser.parse_expression();

            Assert.IsTrue(exp is InstanceExpression);
        }
Пример #3
0
        private void parsesVersionLiteral(String literal)
        {
            OTestParser parser = new OTestParser(literal);
            IExpression exp    = parser.parse_expression();

            Assert.IsTrue(exp is VersionLiteral);
            Assert.AreEqual(literal, "'" + ((VersionLiteral)exp).getValue().ToString() + "'");
        }
Пример #4
0
        public void parsesConstructorFrom1Attribute()
        {
            String                statement = "Company(entity,id=1)";
            OTestParser           parser    = new OTestParser(statement);
            ConstructorExpression c         = parser.parse_constructor_expression();

            Assert.IsNotNull(c);
        }
Пример #5
0
        public void parsesMethodCallExpression()
        {
            String         statement = "print (\"person\" + p.name );";
            OTestParser    parser    = new OTestParser(statement);
            UnresolvedCall ac        = parser.parse_method_call_statement();

            Assert.IsNotNull(ac);
        }
Пример #6
0
        public void parsesHasAnyExpression()
        {
            String      statement = "(1,2,3,4) has any (1,2)";
            OTestParser parser    = new OTestParser(statement);
            IExpression exp       = parser.parse_expression();

            Assert.IsTrue(exp is ContainsExpression);
        }
Пример #7
0
        public void parsesNativeCSharp()
        {
            String      statement = "C#: Console.println(value);";
            OTestParser parser    = new OTestParser(statement);
            NativeCall  call      = parser.parse_native_statement();

            Assert.IsNotNull(call);
            Assert.IsTrue(call is NativeCall);
        }
Пример #8
0
        public void parsesNativeJava()
        {
            String      statement = "Java: System.str.println(value);";
            OTestParser parser    = new OTestParser(statement);
            NativeCall  call      = parser.parse_native_statement();

            Assert.IsNotNull(call);
            Assert.IsTrue(call is NativeCall);
        }
Пример #9
0
        public void parsesAssignmentConstructor()
        {
            String                  statement = "c = Company ( id = 1, name = \"IBM\" );";
            OTestParser             parser    = new OTestParser(statement);
            AssignInstanceStatement a         = parser.parse_assign_instance_statement();

            Assert.IsNotNull(a);
            Assert.IsTrue(a.getExpression() is UnresolvedCall);
        }
Пример #10
0
        public void parsesList2ArgumentsComma()
        {
            String        statement = "Person p, Employee e";
            OTestParser   parser    = new OTestParser(statement);
            ParameterList l         = parser.parse_argument_list();

            Assert.IsNotNull(l);
            Assert.AreEqual(2, l.Count);
        }
Пример #11
0
        public void parsesList1Argument()
        {
            String        statement = "Person p";
            OTestParser   parser    = new OTestParser(statement);
            ParameterList l         = parser.parse_argument_list();

            Assert.IsNotNull(l);
            Assert.AreEqual(1, l.Count);
        }
Пример #12
0
        public void parsesArgument()
        {
            String          statement = "Person p";
            OTestParser     parser    = new OTestParser(statement);
            ITypedParameter a         = parser.parse_typed_argument();

            Assert.IsNotNull(a);
            Assert.AreEqual("Person", a.getType().GetTypeName());
            Assert.AreEqual("p", a.GetName());
        }
Пример #13
0
        public void parsesExpressionWith()
        {
            String      statement = "x = print ( value = \"1\" );";
            OTestParser parser    = new OTestParser(statement);
            IStatement  stmt      = parser.parse_statement();

            Assert.IsNotNull(stmt);
            // Assert.AreEqual(statement, stmt.ToString());
            Assert.AreEqual("x = print(value = \"1\")", generate(stmt));
        }
Пример #14
0
        public void parsesMethodWith()
        {
            String      statement = "print (\"a\", value = \"1\");";
            OTestParser parser    = new OTestParser(statement);
            IStatement  stmt      = parser.parse_statement();

            Assert.IsNotNull(stmt);
            // Assert.AreEqual(statement, stmt.ToString());
            Assert.AreEqual("print(\"a\", value = \"1\")", generate(stmt));
        }
Пример #15
0
        public void parsesSimpleDictLiteral()
        {
            String      statement = "< \"john\" : 1234, eric : 5678 >";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is DictLiteral);
            Assert.AreEqual("<\"john\":1234, eric:5678>", generate(literal)); // not very relevant since the literal is not evaluated yet
        }
Пример #16
0
        public void parsesNativeSymbol()
        {
            String      statement = "ENTITY_1 = \"1\"; ";
            OTestParser parser    = new OTestParser(statement);
            IExpression symbol    = parser.parse_native_symbol();

            Assert.IsNotNull(symbol);
            Assert.IsTrue(symbol is NativeSymbol);
            Assert.AreEqual("\"1\"", ((NativeSymbol)symbol).getExpression().ToString());
        }
Пример #17
0
        public void parsesEmptyDictLiteral()
        {
            String      statement = "<:>";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is DictLiteral);
            Assert.AreEqual("<:>", literal.ToString());
        }
Пример #18
0
        public void parsesArrayAttribute()
        {
            String               statement = "attribute id : Integer[]; ";
            OTestParser          parser    = new OTestParser(statement);
            AttributeDeclaration ad        = parser.parse_attribute_declaration();

            Assert.IsNotNull(ad);
            Assert.AreEqual("id", ad.GetName());
            Assert.AreEqual("Integer[]", ad.getIType().GetTypeName());
        }
Пример #19
0
        public void parsesHexaLiteral()
        {
            String      statement = "0x0A11";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is HexaLiteral);
            Assert.AreEqual("0x0A11", generate(literal));
            Assert.AreEqual(0x0A11, ((HexaLiteral)literal).getValue().LongValue);
        }
Пример #20
0
        public void parsesStringLiteral()
        {
            String      statement = "\"hello\"";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is TextLiteral);
            Assert.AreEqual("\"hello\"", generate(literal));
            Assert.AreEqual("hello", ((TextLiteral)literal).getValue().Value);
        }
Пример #21
0
        public void parsesPeriod()
        {
            String      statement = "'P3Y'";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is PeriodLiteral);
            Assert.AreEqual("'P3Y'", generate(literal));
            Assert.AreEqual(3, ((PeriodLiteral)literal).getValue().Years);
        }
Пример #22
0
        public void parsesDateTimeWithMillis()
        {
            String      statement = "'2012-10-09T15:18:17.487Z'";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is DateTimeLiteral);
            Assert.AreEqual("'2012-10-09T15:18:17.487Z'", literal.ToString());
            Assert.AreEqual(new DateTimeValue(2012, 10, 9, 15, 18, 17, 487), ((DateTimeLiteral)literal).getValue());
        }
Пример #23
0
        public void parsesSimpleTime()
        {
            String      statement = "'15:03:10'";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is TimeLiteral);
            Assert.AreEqual("'15:03:10'", literal.ToString());
            Assert.AreEqual(new TimeValue(15, 03, 10, 0), ((TimeLiteral)literal).getValue());
        }
Пример #24
0
        public void parsesSimpleDate()
        {
            String      statement = "'2012-10-09'";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is DateLiteral);
            Assert.AreEqual("'2012-10-09'", generate(literal));
            Assert.AreEqual(new DateValue(2012, 10, 9), ((DateLiteral)literal).getValue());
        }
Пример #25
0
        public void parsesRange()
        {
            String       statement = "[1..100]";
            OTestParser  parser    = new OTestParser(statement);
            RangeLiteral rl        = parser.parse_range_literal();

            Assert.IsNotNull(rl);
            Assert.AreEqual("1", rl.getFirst().ToString());
            Assert.AreEqual("100", rl.getLast().ToString());
            Assert.AreEqual("[1..100]", generate(rl));
        }
Пример #26
0
        public void parsesDecimalLiteral()
        {
            String      statement = "1234.13";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is DecimalLiteral);
            Assert.AreEqual("1234.13", generate(literal));
            Assert.AreEqual(1234.13, ((DecimalLiteral)literal).getValue().DoubleValue, 0.0000001);
        }
Пример #27
0
        public void parsesIntegerLiteral()
        {
            String      statement = "1234";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is IntegerLiteral);
            Assert.AreEqual("1234", literal.ToString());
            Assert.AreEqual(1234, ((IntegerLiteral)literal).getValue().LongValue);
        }
Пример #28
0
        public void parsesEmptyListLiteral()
        {
            String      statement = "[]";
            OTestParser parser    = new OTestParser(statement);
            IExpression literal   = parser.parse_literal_expression();

            Assert.IsNotNull(literal);
            Assert.IsTrue(literal is ListLiteral);
            Assert.AreEqual("[]", literal.ToString());
            Assert.AreEqual(0, ((ListLiteral)literal).getValue().Count);
        }
Пример #29
0
        public void parsesCategory1Attribute()
        {
            String              statement = "category Person ( id );";
            OTestParser         parser    = new OTestParser(statement);
            CategoryDeclaration cd        = parser.parse_category_declaration();

            Assert.IsNotNull(cd);
            Assert.AreEqual("Person", cd.GetName());
            Assert.IsNull(cd.getDerivedFrom());
            Assert.IsNotNull(cd.GetLocalAttributes());
            Assert.IsTrue(cd.GetLocalAttributes().Contains("id"));
        }
Пример #30
0
        public void parsesNativeMethod()
        {
            String statement = "native method print (String value) {\r\n"
                               + "\tJava: System.str.println(value); \r\n"
                               + "\tC#: Console.println(value); }";

            OTestParser             parser = new OTestParser(statement);
            NativeMethodDeclaration method = parser.parse_native_method_declaration();

            Assert.IsNotNull(method);
            Assert.IsTrue(method is NativeMethodDeclaration);
        }