Ejemplo n.º 1
0
        formatter = GeneralFormatter()
        formattedText = formatter.format(None, '\t')
        expect(formattedText).to_equal(None)

    def test_should_not_format_whitespace(self):
        formatter = GeneralFormatter()
        formattedText = formatter.format(' ', '\t')
        expect(formattedText).to_equal(None)

    def test_should_identify_and_unindent_basic_xml(self):
        formatter = GeneralFormatter()
        formattedText = formatter.unindent(
            '<root>\n\t<child\na="123"></child>\n</root>')
        expect(formattedText).to_equal('<root><child a="123"></child></root>')

    def test_should_identify_and_unindent_basic_json(self):
        formatter = GeneralFormatter()
        formattedText = formatter.unindent(
            '{\n\t"hello": "world",\n\t"value": 123\n}')
        expect(formattedText).to_equal('{"hello":"world","value":123}')


def result_resolver(input):
    formatter = GeneralFormatter()
    return formatter.format(input, '\t')


fs_test.load_testcases(GeneralFormatterTestCases, result_resolver,
                       os.path.dirname(__file__), 'data/indent/*.input.xml',
                       'expected.xml')
Ejemplo n.º 2
0
    def test_should_format_json_on_one_line(self):
        reader = JsonReader('{"hello":\n  "world", // comment\n \'value\':123}')
        formatter = JsonFormatter(
            reader,
            {
                "force_property_quotes": True,
                "remove_comments": True,
                "spacer": "",
                "newline": "",
                "indent_character": "",
            },
        )

        output = formatter.format()
        expect(output).to_equal('{"hello":"world","value":123}')


def result_resolver(input):
    reader = JsonReader(input)
    formatter = JsonFormatter(
        reader, {"force_property_quotes": True, "indent_character": "\t", "normalize_strings": True}
    )

    return formatter.format()


fs_test.load_testcases(
    JsonFormatterTestCase, result_resolver, os.path.dirname(__file__), "../data/format/*.input.json", "expected.json"
)
Ejemplo n.º 3
0
    def test_should_not_format_null_input(self):
        formatter = GeneralFormatter()
        formattedText = formatter.format(None, '\t')
        expect(formattedText).to_equal(None)

    def test_should_not_format_whitespace(self):
        formatter = GeneralFormatter()
        formattedText = formatter.format(' ', '\t')
        expect(formattedText).to_equal(None)

    def test_should_identify_and_unindent_basic_xml(self):
        formatter = GeneralFormatter()
        formattedText = formatter.unindent('<root>\n\t<child\na="123"></child>\n</root>')
        expect(formattedText).to_equal('<root><child a="123"></child></root>')

    def test_should_identify_and_unindent_basic_json(self):
        formatter = GeneralFormatter()
        formattedText = formatter.unindent('{\n\t"hello": "world",\n\t"value": 123\n}')
        expect(formattedText).to_equal('{"hello":"world","value":123}')

def result_resolver(input):
    formatter = GeneralFormatter()
    return formatter.format(input, '\t')

fs_test.load_testcases(
    GeneralFormatterTestCases,
    result_resolver,
    os.path.dirname(__file__),
    'data/indent/*.input.xml',
    'expected.xml')
        renderer = YamlDocumentRenderer(document,
                                        {'force_property_quotes': True})

        output = renderer.render()
        expect(output).to_equal(
            '"\\"hello\\"": world # comment block\nvalue: 123')

    def test_should_preserve_multiple_line_comments_block(self):
        reader = JsonReader(
            '{\'hello\':"world", /* comment block */\n/*comment block*/ \'value\':123}'
        )
        document = document_builder.build(reader)
        renderer = YamlDocumentRenderer(document,
                                        {'force_property_quotes': True})

        output = renderer.render()
        expect(output).to_equal(
            'hello: world # comment block\n# comment block\nvalue: 123')


def result_resolver(input):
    reader = JsonReader(input)
    document = document_builder.build(reader)
    renderer = YamlDocumentRenderer(document, {'indent_character': '\t'})
    return renderer.render()


fs_test.load_testcases(YamlFormatterTestCase, result_resolver,
                       os.path.dirname(__file__),
                       '../data/format/*.input.json', 'expected.yaml')
        expect(output).to_equal('obj:\n  hello: world\n  # comment\n  # block\n  value: 123')

    def test_should_preserve_in_line_comment_block(self):
        reader = JsonReader('{\'"hello"\':"world", /* comment block */ \'value\':123}')
        document = document_builder.build(reader)
        renderer = YamlDocumentRenderer(document, {'force_property_quotes': True})

        output = renderer.render()
        expect(output).to_equal('"\\"hello\\"": world # comment block\nvalue: 123')

    def test_should_preserve_multiple_line_comments_block(self):
        reader = JsonReader('{\'hello\':"world", /* comment block */\n/*comment block*/ \'value\':123}')
        document = document_builder.build(reader)
        renderer = YamlDocumentRenderer(document, {'force_property_quotes': True})

        output = renderer.render()
        expect(output).to_equal('hello: world # comment block\n# comment block\nvalue: 123')

def result_resolver(input):
    reader = JsonReader(input)
    document = document_builder.build(reader)
    renderer = YamlDocumentRenderer(document, {'indent_character': '\t'})
    return renderer.render()

fs_test.load_testcases(
    YamlFormatterTestCase,
    result_resolver,
    os.path.dirname(__file__),
    '../data/format/*.input.json',
    'expected.yaml')