示例#1
0
def test_formatting_api_call_pretty(parser):
    visitor = FormattingVisitor(pretty=True)
    nodes = parser.parse('''get / conn =  1 runas = "foo"
{
  "a"   :
"b", "q": [
1,
2]}''')

    assert visitor.visit(nodes[0]) == '''get / conn=1 runas="foo"
示例#2
0
def test_formatting_pretty(parser):
    visitor = FormattingVisitor(pretty=True)
    nodes = parser.parse('''for x in [1,2] {
    let a = { 1: 2, 3: 4, 'foo': [42, "hello"]}
    echo a x
    for y in c {
        echo [1, 3, 5] b={'foo': 42, "bar": [6, 7, [8, 9]]}
        GET /path
        {"foo": {"q": [1, 2,{'x': [3, "5", {}]}]}}
    }
}''')
    assert visitor.visit(nodes[0]) == '''for x in [
示例#3
0
def test_formatting_for_in_compact(parser):
    visitor = FormattingVisitor(pretty=False)
    nodes = parser.parse('''for a in [1, 2, 3] {
        echo a
        for b in c {
            echo b
            let x = b
        }
        echo a + 1
    }''')

    assert visitor.visit(nodes[0]) == '''for a in [1,2,3] {
示例#4
0
def test_formatting_api_call_compact(parser):
    visitor = FormattingVisitor()

    nodes = parser.parse('''get / conn =  1 runas = "foo"
{
  "a"   :
"b", "q": [
1,
2]}''')

    assert visitor.visit(nodes[0]) == '''get / conn=1 runas="foo"
{"a":"b","q":[1,2]}
'''
    nodes = parser.parse('get ("foo" + "/" + 42 + "/" + 1)')
    assert visitor.visit(nodes[0]) == 'get ("foo"+"/"+42+"/"+1)\n'
示例#5
0
def test_formatting_symbol_inside_dict(parser):
    nodes = parser.parse('''POST _search
{
  'foo': {
    'bar': r.@id
  }
}''')
    assert FormattingVisitor(pretty=False).visit(nodes[0]) == '''POST _search
示例#6
0
def test_formatting_looped_api_calls(parser):
    nodes = parser.parse('''for i in range(@foo @bar 1 10 a=4 b=2) {
  POST test-1/_doc
  { "tag": i }
  POST test-2/_doc
  { "tag": i + 1}
}
''')

    assert FormattingVisitor(pretty=True).visit(nodes[0]) == '''for i in range(@foo, @bar, 1, 10, a=4, b=2) {
  POST test-1/_doc
  {
    "tag": i
  }

  POST test-2/_doc
  {
    "tag": i+1
  }

}'''

    assert FormattingVisitor(pretty=False).visit(nodes[0]) == '''for i in range(@foo,@bar,1,10,a=4,b=2) {
示例#7
0
 def save(self, output_file):
     content = []
     for node in self.nodes:
         content.append(FormattingVisitor(pretty=True).visit(node))
     with open(output_file, 'w') as outs:
         outs.write('\n'.join(content))
示例#8
0
def test_formatting_func_call(parser):
    visitor = FormattingVisitor()
    nodes = parser.parse('''f @abc 1 "a" b=a foo="bar"''')

    assert visitor.visit(nodes[0]) == '''f @abc 1 "a" b=a foo="bar"'''