Ejemplo n.º 1
0
def test_json():
    test = ["key: [86, 95, 12] # json 1.r"]
    line = 0
    index = 1
    anal = ChangeAnalyzer(line, index, test)
    #init class
    assert anal._area[0] == test[0]
    #key possition
    assert anal.get_pos_type() is PosType.in_key
    index = 5
    anal = ChangeAnalyzer(line, index, test)
    #value possition 1
    assert anal.get_pos_type() is PosType.in_value
    index = 8
    anal = ChangeAnalyzer(line, index, test)
    #value possition 2
    assert anal.get_pos_type() is PosType.in_value
    index = 20
    anal = ChangeAnalyzer(line, index, test)
    #comment possition
    assert anal.get_pos_type() is PosType.comment
    index = 7
    anal = ChangeAnalyzer(line, index, test)
    #inner possition
    assert anal.get_pos_type() is PosType.in_inner
    # uncomment function
    assert LineAnalyzer.strip_comment(test[0]) == "key: [86, 95, 12]"
    assert LineAnalyzer.strip_comment(
        "key: [86, 95, 12]     # json 1.r") == "key: [86, 95, 12]"
    # identation
    assert LineAnalyzer.indent_changed("test1", "test2") is False
    assert LineAnalyzer.indent_changed("   test1", "  test2") is True

    test = ["key: {key1: 86,key2: 95, key3: 12} # json 1.r"]
    line = 0
    index = 3
    anal = ChangeAnalyzer(line, index, test)
    #init class
    assert anal._area[0] == test[0]
    #key possition
    assert anal.get_pos_type() is PosType.in_key
    index = 5
    anal = ChangeAnalyzer(line, index, test)
    #value possition 1
    assert anal.get_pos_type() is PosType.in_value
    index = 11
    anal = ChangeAnalyzer(line, index, test)
    #value possition 2
    assert anal.get_pos_type() is PosType.in_value
    index = 40
    anal = ChangeAnalyzer(line, index, test)
    #comment possition
    assert anal.get_pos_type() is PosType.comment
    index = 7
    anal = ChangeAnalyzer(line, index, test)
    #inner possition
    assert anal.get_pos_type() is PosType.in_inner
Ejemplo n.º 2
0
def test_strip_comment(line, expected):
    assert LineAnalyzer.strip_comment(line) == expected