Beispiel #1
0
    def testSimpleScopeByteString(self):
        scope_config = {sid("foo"): {vid("bar"): "BAR", vid("baz"): "BAZ"}}
        subst = interpolation.Substitution(var_config={},
                                           scope_config=scope_config)

        self.assertEqual(subst.Substitute(b"%%foo.bar%% %%foo.baz%%"),
                         b"BAR BAZ")
Beispiel #2
0
    def testMultipleVarUnicodeString(self):
        var_config = {vid("foo"): "FOO", vid("bar"): "BAR", vid("baz"): "BAZ"}
        subst = interpolation.Substitution(var_config=var_config,
                                           scope_config={})

        self.assertEqual(subst.Substitute("%%foo%% %%bar%% %%baz%%"),
                         "FOO BAR BAZ")
Beispiel #3
0
    def testMultipleVarByteString(self):
        var_config = {vid("foo"): 42, vid("bar"): "BAR", vid("baz"): 1337}
        subst = interpolation.Substitution(var_config=var_config,
                                           scope_config={})

        self.assertEqual(subst.Substitute(b"%%foo%% %%bar%% %%baz%%"),
                         b"42 BAR 1337")
Beispiel #4
0
    def testVarAndScope(self):
        var_config = {vid("foo"): "FOO"}
        scope_config = {sid("quux"): {vid("bar"): "BAR", vid("baz"): "BAZ"}}
        subst = interpolation.Substitution(var_config=var_config,
                                           scope_config=scope_config)

        pattern = "%%foo%% %%quux.bar%% %%quux.baz%%"
        self.assertEqual(subst.Substitute(pattern), "FOO BAR BAZ")
Beispiel #5
0
    def testInterpolationHappensSimultaneously(self):
        var_config = {vid("foo"): "%%bar%%", vid("bar"): "%%quux.norf%%"}
        scope_config = {
            sid("quux"): {
                vid("norf"): "%%foo%%",
                vid("thud"): "%%quux.norf%%"
            }
        }
        subst = interpolation.Substitution(var_config=var_config,
                                           scope_config=scope_config)

        pattern = "%%foo%% %%bar%% %%quux.norf%% %%quux.thud%%"
        output = "%%bar%% %%quux.norf%% %%foo%% %%quux.norf%%"
        self.assertEqual(subst.Substitute(pattern), output)
Beispiel #6
0
  def testMultipleScopeByteString(self):
    scope_config = {
        sid("foo"): {
            vid("bar"): 2,
            vid("baz"): 3
        },
        sid("quux"): {
            vid("norf"): 5,
            vid("thud"): 7
        },
    }
    subst = interpolation.Substitution(var_config={}, scope_config=scope_config)

    pattern = b"%%foo.bar%% %%foo.baz%% %%quux.norf%% %%quux.thud%%"
    self.assertEqual(subst.Substitute(pattern), b"2 3 5 7")
Beispiel #7
0
  def testMultipleScopeUnicodeString(self):
    scope_config = {
        sid("foo"): {
            vid("bar"): "BAR",
            vid("baz"): "BAZ"
        },
        sid("quux"): {
            vid("norf"): "NORF",
            vid("thud"): "THUD"
        },
    }
    subst = interpolation.Substitution(var_config={}, scope_config=scope_config)

    pattern = "%%foo.bar%% %%foo.baz%% %%quux.norf%% %%quux.thud%%"
    self.assertEqual(subst.Substitute(pattern), "BAR BAZ NORF THUD")
Beispiel #8
0
    def testSimpleVarByteString(self):
        var_config = {vid("foo"): 42}
        subst = interpolation.Substitution(var_config=var_config,
                                           scope_config={})

        self.assertEqual(subst.Substitute(b"%%foo%%"), b"42")
Beispiel #9
0
    def testSimpleVarUnicodeString(self):
        var_config = {vid("foo"): 108}
        subst = interpolation.Substitution(var_config=var_config,
                                           scope_config={})

        self.assertEqual(subst.Substitute("%%foo%%"), "108")
Beispiel #10
0
 def testNoPlaceholdersByteString(self):
     subst = interpolation.Substitution(var_config={}, scope_config={})
     self.assertEqual(subst.Substitute(b"FOOBARBAZ"), b"FOOBARBAZ")
Beispiel #11
0
 def testNoPlaceholdersUnicodeString(self):
     subst = interpolation.Substitution(var_config={}, scope_config={})
     self.assertEqual(subst.Substitute("foo bar baz"), "foo bar baz")
Beispiel #12
0
 def testMultipleVariableOccurences(self):
     var_config = {vid("foo"): 42}
     subst = interpolation.Substitution(var_config=var_config,
                                        scope_config={})
     self.assertEqual(subst.Substitute("%%foo%% %%foo%% %%foo%%"),
                      "42 42 42")