tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_error_lineno.py (1004B)


      1 import WebIDL
      2 
      3 
      4 def WebIDLTest(parser, harness):
      5    # Check that error messages put the '^' in the right place.
      6 
      7    threw = False
      8    input = """\
      9 // This is a comment.
     10 interface Foo {
     11 };
     12 
     13 /* This is also a comment. */
     14 interface ?"""
     15    try:
     16        parser.parse(input)
     17        parser.finish()
     18    except WebIDL.WebIDLError as e:
     19        threw = True
     20        lines = str(e).split("\n")
     21 
     22        harness.check(len(lines), 3, "Expected number of lines in error message")
     23        harness.ok(
     24            lines[0].endswith("line 6:10"),
     25            'First line of error should end with "line 6:10", but was "%s".' % lines[0],
     26        )
     27        harness.check(
     28            lines[1],
     29            "interface ?",
     30            "Second line of error message is the line which caused the error.",
     31        )
     32        harness.check(
     33            lines[2],
     34            " " * (len("interface ?") - 1) + "^",
     35            "Correct column pointer in error message.",
     36        )
     37 
     38    harness.ok(threw, "Should have thrown.")