def test_var_property(self): src = """Item { property var varProperty: { "key1": "value1", "key2": "value2" } }""" lexer = Lexer(src) lexer.tokenize() qmlclass = QmlClass("Foo") qmlparser.parse(lexer.tokens, qmlclass) properties = qmlclass.get_properties() self.assertEqual(properties[0].name, "varProperty") self.assertEqual(properties[0].type, "var")
def test_function_property(self): src = """Item { property var fnProperty: function (arg1, arg2) { return arg1 + arg2; } }""" lexer = Lexer(src) lexer.tokenize() qmlclass = QmlClass("Foo") qmlparser.parse(lexer.tokens, qmlclass) properties = qmlclass.get_properties() self.assertEqual(properties[0].name, "fnProperty") self.assertEqual(properties[0].type, "var")
def test_readonly_property(self): src = """Item { /// v1 doc readonly property int v1 /// v2 doc property int v2 }""" lexer = Lexer(src) lexer.tokenize() qmlclass = QmlClass("Foo") qmlparser.parse(lexer.tokens, qmlclass) properties = qmlclass.get_properties() self.assertEqual(properties[0].name, "v1") self.assertEqual(properties[0].type, "int") self.assertEqual(properties[0].doc, "/// v1 doc") self.assert_(properties[0].is_readonly) self.assertEqual(properties[1].name, "v2") self.assertEqual(properties[1].type, "int") self.assertEqual(properties[1].doc, "/// v2 doc") self.assert_(not properties[1].is_readonly)