Exemplo n.º 1
0
def test_mustache_splitting():
    assert MustacheParser.split("{{foo}}") == [ref("foo")]
    assert MustacheParser.split("{{&foo}}") == ["{{foo}}"]
    splits = MustacheParser.split('blech {{foo}} {{bar}} bonk {{&baz}} bling')
    assert splits == [
        'blech ',
        ref("foo"), ' ',
        ref('bar'), ' bonk ', '{{baz}}', ' bling'
    ]
Exemplo n.º 2
0
def test_mustache_joining():
    oe = Environment(foo="foo herp", bar="bar derp", baz="baz blerp")

    joined, unbound = MustacheParser.join(MustacheParser.split("{{foo}}"), oe)
    assert joined == "foo herp"
    assert unbound == []

    splits = MustacheParser.split('blech {{foo}} {{bar}} bonk {{&baz}} bling')
    joined, unbound = MustacheParser.join(splits, oe)
    assert joined == 'blech foo herp bar derp bonk {{baz}} bling'
    assert unbound == []

    splits = MustacheParser.split('{{foo}} {{bar}} {{unbound}}')
    joined, unbound = MustacheParser.join(splits, oe)
    assert joined == 'foo herp bar derp {{unbound}}'
    assert unbound == [Ref.from_address('unbound')]
Exemplo n.º 3
0
def test_mustache_joining():
  oe = Environment(foo = "foo herp",
                   bar = "bar derp",
                   baz = "baz blerp")

  joined, unbound = MustacheParser.join(MustacheParser.split("{{foo}}"), oe)
  assert joined == "foo herp"
  assert unbound == []

  splits = MustacheParser.split('blech {{foo}} {{bar}} bonk {{&baz}} bling')
  joined, unbound = MustacheParser.join(splits, oe)
  assert joined == 'blech foo herp bar derp bonk {{baz}} bling'
  assert unbound == []

  splits = MustacheParser.split('{{foo}} {{bar}} {{unbound}}')
  joined, unbound = MustacheParser.join(splits, oe)
  assert joined == 'foo herp bar derp {{unbound}}'
  assert unbound == [Ref.from_address('unbound')]
Exemplo n.º 4
0
def test_mustache_splitting():
  assert MustacheParser.split("{{foo}}") == [ref("foo")]
  assert MustacheParser.split("{{&foo}}") == ["{{foo}}"]
  splits = MustacheParser.split('blech {{foo}} {{bar}} bonk {{&baz}} bling')
  assert splits == ['blech ', ref("foo"), ' ', ref('bar'), ' bonk ', '{{baz}}', ' bling']
Exemplo n.º 5
0
def test_mustache_re():
  assert MustacheParser.split("{{foo}}") == [ref("foo")]
  assert MustacheParser.split("{{_}}") == [ref("_")]
  with pytest.raises(Ref.InvalidRefError):
    MustacheParser.split("{{4}}")
  def chrange(a,b):
    return ''.join(map(lambda ch: str(chr(ch)), range(ord(a), ord(b)+1)))
  slash_w = chrange('a','z') + chrange('A','Z') + chrange('0','9') + '_'
  assert MustacheParser.split("{{%s}}" % slash_w) == [ref(slash_w)]

  # bracketing
  assert MustacheParser.split("{{{foo}}") == ['{', ref('foo')]
  assert MustacheParser.split("{{foo}}}") == [ref('foo'), '}']
  assert MustacheParser.split("{{{foo}}}") == ['{', ref('foo'), '}']
  assert MustacheParser.split("{{}}") == ['{{}}']
  assert MustacheParser.split("{{{}}}") == ['{{{}}}']
  assert MustacheParser.split("{{{{foo}}}}") == ['{{', ref("foo"), '}}']

  invalid_refs = ['!@', '-', '$', ':']
  for val in invalid_refs:
    with pytest.raises(Ref.InvalidRefError):
      MustacheParser.split("{{%s}}" % val)
Exemplo n.º 6
0
def test_mustache_re():
    assert MustacheParser.split("{{foo}}") == [ref("foo")]
    assert MustacheParser.split("{{_}}") == [ref("_")]
    with pytest.raises(Ref.InvalidRefError):
        MustacheParser.split("{{4}}")

    def chrange(a, b):
        return ''.join(map(lambda ch: str(chr(ch)), range(ord(a), ord(b) + 1)))

    slash_w = chrange('a', 'z') + chrange('A', 'Z') + chrange('0', '9') + '_'
    assert MustacheParser.split("{{%s}}" % slash_w) == [ref(slash_w)]

    # bracketing
    assert MustacheParser.split("{{{foo}}") == ['{', ref('foo')]
    assert MustacheParser.split("{{foo}}}") == [ref('foo'), '}']
    assert MustacheParser.split("{{{foo}}}") == ['{', ref('foo'), '}']
    assert MustacheParser.split("{{}}") == ['{{}}']
    assert MustacheParser.split("{{{}}}") == ['{{{}}}']
    assert MustacheParser.split("{{{{foo}}}}") == ['{{', ref("foo"), '}}']

    invalid_refs = ['!@', '-', '$', ':']
    for val in invalid_refs:
        with pytest.raises(Ref.InvalidRefError):
            MustacheParser.split("{{%s}}" % val)