def test_concat_str(self): jbos, lit = safe_str.jbos, safe_str.literal fn = syntax_string(jbos(lit('$(fn '), '1', lit(','), '2', lit(')')), Syntax.function) self.assertEqual(Function('fn', '1', '2') + 'foo', jbos(fn, 'foo')) self.assertEqual('foo' + Function('fn', '1', '2'), jbos('foo', fn)) fn = syntax_string(jbos(lit('$(fn '), '1', lit(','), '2', lit(')')), Syntax.function, True) self.assertEqual( Function('fn', '1', '2', quoted=True) + 'foo', jbos(fn, 'foo')) self.assertEqual('foo' + Function('fn', '1', '2', quoted=True), jbos('foo', fn))
def test_concat_var(self): jbos, lit = safe_str.jbos, safe_str.literal foo = syntax_string(jbos(lit('$(foo '), '1', lit(','), '2', lit(')')), Syntax.function) bar = syntax_string(jbos(lit('$(bar '), '3', lit(','), '4', lit(')')), Syntax.function) self.assertEqual( Function('foo', '1', '2') + Function('bar', '3', '4'), jbos(foo, bar)) foo = syntax_string(jbos(lit('$(foo '), '1', lit(','), '2', lit(')')), Syntax.function, True) self.assertEqual((Function('foo', '1', '2', quoted=True) + Function('bar', '3', '4')), jbos(foo, bar))
def test_use(self): jbos, lit = safe_str.jbos, safe_str.literal self.assertEqual( Function('fn').use(), syntax_string(jbos(lit('$(fn)')), Syntax.function)) self.assertEqual( Function('fn', '1', '2').use(), syntax_string(jbos(lit('$(fn '), '1', lit(','), '2', lit(')')), Syntax.function)) self.assertEqual( Function('fn', ['a', 'b'], ['1', '2']).use(), syntax_string( jbos(lit('$(fn '), 'a', lit(' '), 'b', lit(','), '1', lit(' '), '2', lit(')')), Syntax.function))
def test_clean(self): jbos, lit = safe_str.jbos, safe_str.literal fn = syntax_string(jbos(lit('$(fn '), '1,2', lit(')'))) out = self.make_writer() out.write(fn, Syntax.clean) self.assertEqual(out.stream.getvalue(), '$(fn 1,2)') fn = syntax_string(jbos(lit('$(fn '), '1,2', lit(')')), Syntax.function) out = self.make_writer() out.write(fn, Syntax.clean) self.assertEqual(out.stream.getvalue(), '$(fn 1$,2)') fn = syntax_string(jbos(lit('$(fn '), '1,2', lit(')')), quoted=True) out = self.make_writer() out.write(fn, Syntax.clean) self.assertEqual(out.stream.getvalue(), "'$(fn 1,2)'")