mirror of
https://github.com/MarkParker5/STARK.git
synced 2024-11-24 08:12:13 +02:00
8d4687b628
add validations and tests
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import pytest
|
|
from VICore import VIObject, VIWord, Pattern
|
|
from VICore.VIObjects.VIObject import classproperty
|
|
|
|
|
|
class VIFullName(VIObject):
|
|
first: VIWord
|
|
second: VIWord
|
|
|
|
@classproperty
|
|
def pattern(cls) -> Pattern:
|
|
return Pattern('$first:VIWord $second:VIWord')
|
|
|
|
class ExtraParameterInAnnotation(VIObject):
|
|
word1: VIWord = None
|
|
word2: VIWord = None
|
|
word3: VIWord = None
|
|
|
|
@classproperty
|
|
def pattern(cls) -> Pattern:
|
|
return Pattern('$word1:VIWord $word2:VIWord')
|
|
|
|
def test_nested_viobjects():
|
|
Pattern.add_parameter_type(VIFullName)
|
|
|
|
p = Pattern('$name:VIFullName')
|
|
assert p
|
|
assert p.compiled
|
|
|
|
m = p.match('John Galt')
|
|
assert m
|
|
assert set(m.parameters.keys()) == {'name'}
|
|
assert m.parameters['name'].first == VIWord('John')
|
|
assert m.parameters['name'].second == VIWord('Galt')
|
|
|
|
def test_extra_parameter_in_annotation():
|
|
Pattern.add_parameter_type(ExtraParameterInAnnotation)
|
|
|
|
p = Pattern('$name:ExtraParameterInAnnotation')
|
|
assert p
|
|
assert p.compiled
|
|
|
|
m = p.match('John Galt')
|
|
assert m
|
|
assert set(m.parameters.keys()) == {'name'}
|
|
assert m.parameters['name'].word1 == VIWord('John')
|
|
assert m.parameters['name'].word2 == VIWord('Galt')
|
|
assert m.parameters['name'].word3 == None |