from api_object_spec import model
from api_object_spec.compile import ApiSpecification

result = model.KeyValue(
    model.Pair(
        model.Token('string'),
    )
)

print result

assert result.match({'wutever': 'yes'})

t = ApiSpecification('''
    token = "<PASSWORD>": <number>
    token = "<PASSWORD>": "<PASSWORD>"
    token = "<PASSWORD>": "<PASSWORD>"
    token = "<PASSWORD>": <object>

    pair = {<token>...}
''')

print t.generate('pair')

examples = [
    {"yessir": {}, "yessir": "dressir"},
    {'boogie': 1}
]

bad_examples = [
    {'not a key': 1}
]

for e in examples:
    r = t.validate('o', e)
    assert r

for e in bad_examples:
    r = t.validate('o', e)
    print r.trace(), 'bad result'

    assert not r

t = ApiSpecification('token = {"1": <number>}')
t = ApiSpecification('''
    token = <string>: {
        "1": <number>
    }
''')


from api_object_spec import model
from api_object_spec.compile import ApiSpecification

result = model.KeyValue(
    model.Pair(
        model.Token('string'),
    )
)

print result

assert result.match({'wutever': 'yes'})

t = ApiSpecification('''
    token = "<PASSWORD>": <number>
    token = "<PASSWORD>": "<PASSWORD>"
    token = "<PASSWORD>": "<PASSWORD>"
    token = "<PASSWORD>": <object>

    pair = {<token>...}
''')

print t.generate('pair')

examples = [
    {"yessir": {}, "yessir": "dressir"},
    {'boogie': 1}
]

bad_examples = [
    {'not a key': 1}
]

for e in examples:
    r = t.validate('o', e)
    assert r

for e in bad_examples:
    r = t.validate('o', e)
    print r.trace(), 'bad result'

    assert not r

t = ApiSpecification('token = {"1": <number>}')
t = ApiSpecification('''
    token = <string>: {
        "1": <number>
    }
''')


token = "<PASSWORD>": <number>     token = "<PASSWORD>": "<PASSWORD>"     token = "<PASSWORD>": "<PASSWORD>"     token = "<PASSWORD>": <object>      pair = {<token>...} token = <string>: {         "1": <number>     }