示例#1
0
def test_interpolate_expr():
    from kid.codewriter import interpolate
    tests = [ ('foo ${bar} baz', ["'foo '", "bar", "' baz'"]),
              ('foo $bar baz', ["'foo '", "bar", "' baz'"]),
              ('foo $${bar} baz', 'foo ${bar} baz'),
              ('foo $$bar baz', 'foo $bar baz'),
              ('${foo} bar baz', ["foo", "' bar baz'"]),
              ('$foo bar baz', ["foo", "' bar baz'"]),
              ('foo bar ${baz}', ["'foo bar '", "baz"]),
              ('foo bar $baz', ["'foo bar '", "baz"]),
              ('foo $${bar}${baz}', ["'foo ${bar}'", "baz"]),
              ('foo $$bar$baz', ["'foo $bar'", "baz"]),
              ('${foo} bar ${baz}', ["foo", "' bar '", "baz"]),
              ('$foo bar $baz', ["foo", "' bar '", "baz"]),
              ('${foo}$${bar}${baz}', ["foo", "'${bar}'", "baz"]),
              ('$foo$$bar$baz', ["foo", "'$bar'", "baz"]),
              ('foo $object.attr bar', ["'foo '", "object.attr", "' bar'"]),
              ('$ foo ${bar baz}', ["'$ foo '", 'bar baz']),
              ('foo$ ${bar.baz}', ["'foo$ '", 'bar.baz']),
              ('$foo $100 $bar', ["foo", "' $100 '", "bar"]),
              ('$foo $$100 $bar', ["foo", "' $100 '", "bar"]),
              ('$$foo', '$foo'),
              ('', '')]
    for test, expect in tests:
        actual = interpolate(test)
        assert actual == expect
示例#2
0
def test_interpolate_expr():
    from kid.codewriter import interpolate
    tests = [('foo ${bar} baz', ["'foo '", "bar", "' baz'"]),
             ('foo $bar baz', ["'foo '", "bar", "' baz'"]),
             ('foo $${bar} baz', 'foo ${bar} baz'),
             ('foo $$bar baz', 'foo $bar baz'),
             ('${foo} bar baz', ["foo", "' bar baz'"]),
             ('$foo bar baz', ["foo", "' bar baz'"]),
             ('foo bar ${baz}', ["'foo bar '", "baz"]),
             ('foo bar $baz', ["'foo bar '", "baz"]),
             ('foo $${bar}${baz}', ["'foo ${bar}'", "baz"]),
             ('foo $$bar$baz', ["'foo $bar'", "baz"]),
             ('${foo} bar ${baz}', ["foo", "' bar '", "baz"]),
             ('$foo bar $baz', ["foo", "' bar '", "baz"]),
             ('${foo}$${bar}${baz}', ["foo", "'${bar}'", "baz"]),
             ('$foo$$bar$baz', ["foo", "'$bar'", "baz"]),
             ('foo $object.attr bar', ["'foo '", "object.attr", "' bar'"]),
             ('$ foo ${bar baz}', ["'$ foo '", 'bar baz']),
             ('foo$ ${bar.baz}', ["'foo$ '", 'bar.baz']),
             ('$foo $100 $bar', ["foo", "' $100 '", "bar"]),
             ('$foo $$100 $bar', ["foo", "' $100 '", "bar"]),
             ('$$foo', '$foo'), ('', '')]
    for test, expect in tests:
        actual = interpolate(test)
        assert actual == expect
示例#3
0
 def process_text(is_attribute, k, tag):
     key = None
     s = _py_i18n_re.search(k)
     if s:
         key = (s.group(1) or s.group(2) or '').strip()
     elif not is_attribute:
         # we don't have a kid expression in there, so it is
         # "just" a text entry - which we want to be translated!
         import kid.codewriter as cw
         parts = cw.interpolate(k)
         if isinstance(parts, list) and len(parts) > 1:
             print "Warning: Mixed content in tag <%s>: %s" % (tag, k)
         elif isinstance(parts, basestring):
             key = k.strip()
     if key and (key not in keys) and (tag not in tags_to_ignore):
         messages.append((tag, fname, key))
         keys.append(key)
示例#4
0
 def process_text(is_attribute, k, tag):
     key = None
     s = _py_i18n_re.search(k)
     if s:
         key = (s.group(1) or s.group(2) or '').strip()
     elif not is_attribute:
         # we don't have a kid expression in there, so it is
         # "just" a text entry - which we want to be translated!
         import kid.codewriter as cw
         parts = cw.interpolate(k)
         if isinstance(parts, list) and len(parts) > 1:
             print "Warning: Mixed content in tag <%s>: %s" % (tag, k)
         elif isinstance(parts, basestring):
             key = k.strip()
     if key and key not in keys and tag not in tags_to_ignore:
         messages.append((tag, fname, key))
         keys.append(key)
示例#5
0
def test_interpolate_object():
    from kid.codewriter import interpolate
    expr = interpolate("foo ${bar} baz")
    assert repr(expr) == "['foo ', bar, ' baz']"
    # test for ticket #79
    assert repr(interpolate('$foo')) == '[foo]'
示例#6
0
def test_interpolate_object():
    from kid.codewriter import interpolate
    expr = interpolate("foo ${bar} baz")
    assert repr(expr) == "['foo ', bar, ' baz']"
    # test for ticket #79
    assert repr(interpolate('$foo')) == '[foo]'