|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import unittest |
|
|
|
|
|
from .common import run_js |
|
|
|
|
|
|
|
|
class TestJsonSlicerYajlFlags(unittest.TestCase): |
|
|
def test_yajl_allow_comments_off(self): |
|
|
with self.assertRaises(RuntimeError): |
|
|
run_js('1 // comment', yajl_allow_comments=False) |
|
|
|
|
|
def test_yajl_allow_comments_on(self): |
|
|
self.assertEqual( |
|
|
run_js('1 // comment', yajl_allow_comments=True), |
|
|
[1] |
|
|
) |
|
|
|
|
|
def test_yajl_dont_validate_strings_off(self): |
|
|
with self.assertRaises(RuntimeError): |
|
|
run_js(b'"\xff"', binary=True, yajl_dont_validate_strings=False) |
|
|
|
|
|
def test_yajl_dont_validate_strings_on(self): |
|
|
self.assertEqual( |
|
|
run_js(b'"\xff"', binary=True, yajl_dont_validate_strings=True), |
|
|
[b'\xff'] |
|
|
) |
|
|
|
|
|
def test_yajl_allow_trailing_garbage_off(self): |
|
|
with self.assertRaises(RuntimeError): |
|
|
run_js('{}{}', yajl_allow_trailing_garbage=False) |
|
|
|
|
|
def test_yajl_allow_trailing_garbage_on(self): |
|
|
self.assertEqual( |
|
|
run_js('{}{}', yajl_allow_trailing_garbage=True), |
|
|
[{}] |
|
|
) |
|
|
|
|
|
def test_yajl_allow_multiple_values_off(self): |
|
|
with self.assertRaises(RuntimeError): |
|
|
run_js('{}{}', yajl_allow_multiple_values=False) |
|
|
|
|
|
def test_yajl_allow_multiple_values_on(self): |
|
|
self.assertEqual( |
|
|
run_js('{}{}', yajl_allow_multiple_values=True), |
|
|
[{}, {}] |
|
|
) |
|
|
|
|
|
def test_yajl_allow_partial_values_off(self): |
|
|
with self.assertRaises(RuntimeError): |
|
|
run_js('[1', (None,), yajl_allow_partial_values=False) |
|
|
|
|
|
def test_yajl_allow_partial_values_on(self): |
|
|
self.assertEqual( |
|
|
run_js('[1', (None,), yajl_allow_partial_values=True), |
|
|
[1] |
|
|
) |
|
|
|
|
|
def test_yajl_verbose_errors_on(self): |
|
|
with self.assertRaises(RuntimeError) as e: |
|
|
run_js('', (None,), yajl_verbose_errors=True) |
|
|
|
|
|
self.assertTrue('premature EOF' in str(e.exception)) |
|
|
self.assertTrue('--^' in str(e.exception)) |
|
|
|
|
|
def test_yajl_verbose_errors_off(self): |
|
|
with self.assertRaises(RuntimeError) as e: |
|
|
run_js('', (None,), yajl_verbose_errors=False) |
|
|
|
|
|
self.assertTrue('premature EOF' in str(e.exception)) |
|
|
self.assertTrue('--^' not in str(e.exception)) |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
unittest.main() |
|
|
|