diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/in/com.pelagicore.test.qface | 15 | ||||
-rw-r--r-- | tests/in/values.qface | 13 | ||||
-rw-r--r-- | tests/test_parser.py | 8 | ||||
-rw-r--r-- | tests/test_values.py | 36 |
4 files changed, 64 insertions, 8 deletions
diff --git a/tests/in/com.pelagicore.test.qface b/tests/in/com.pelagicore.test.qface index ae8a4f0..a5be518 100644 --- a/tests/in/com.pelagicore.test.qface +++ b/tests/in/com.pelagicore.test.qface @@ -2,13 +2,12 @@ module com.pelagicore.test 1.0; import common 1.0; -@service: { singleton: true} interface ContactService { State state; - int intValue; - readonly string stringValue; - bool boolValue; - real realValue; + int intValue = "2"; + readonly string stringValue = "hello"; + bool boolValue = "true"; + real realValue = "0.1"; var varValue; Contact currentContact; common.Date today; @@ -39,7 +38,7 @@ flag Phase { * The contact information */ struct Contact { - string name; - int age; - bool isMarried; + string name = "name"; + int age = "99"; + bool isMarried = "false"; } diff --git a/tests/in/values.qface b/tests/in/values.qface new file mode 100644 index 0000000..3b7035d --- /dev/null +++ b/tests/in/values.qface @@ -0,0 +1,13 @@ +module values 1.0 + +interface Namespace { + int intValue = "99" + real realValue = "0.99" + string message = "foo" + Person person = '{ name: "Hello", age: 101 }' +} + +struct Person { + string name = "hello"; + int age = "99"; +}
\ No newline at end of file diff --git a/tests/test_parser.py b/tests/test_parser.py index 61d680c..62b661c 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -261,3 +261,11 @@ def test_parser_exceptions(): system = FileSystem.parse_document('not-exists') +def test_default_values(): + system = load_test() + interface = system.lookup('com.pelagicore.test.ContactService') + symbol = system.lookup('com.pelagicore.test.ContactService#intValue') + assert symbol.value == "2" + symbol = system.lookup('com.pelagicore.test.ContactService#realValue') + assert symbol.value == "0.1" + diff --git a/tests/test_values.py b/tests/test_values.py new file mode 100644 index 0000000..9ce93d1 --- /dev/null +++ b/tests/test_values.py @@ -0,0 +1,36 @@ +from qface.generator import FileSystem +import logging +import logging.config +from path import Path + + +# logging.config.fileConfig('logging.ini') +logging.basicConfig() + +log = logging.getLogger(__name__) + +inputPath = Path('tests/in') + + +def loadValues(): + path = inputPath / 'values.qface' + return FileSystem.parse_document(path) + + +def test_values(): + system = loadValues() + assert system + # lookup module + interface = system.lookup('values.Namespace') + assert interface + properties = interface._propertyMap + assert properties['intValue'].value == "99" + assert properties['realValue'].value == "0.99" + assert properties['message'].value == "foo" + assert properties['person'].value == '{ name: "Hello", age: 101 }' + struct = system.lookup('values.Person') + assert struct + fields = struct._fieldMap + assert fields["name"].value == "hello" + assert fields["age"].value == "99" + |