Skip to content

Commit 5d07f83

Browse files
committed
Add tests for encoding comments
1 parent 45b97df commit 5d07f83

File tree

1 file changed

+26
-1
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests

1 file changed

+26
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_exec.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -311,3 +311,28 @@ def __getitem__(self, key):
311311
exec("global x; x = y", ns, m)
312312
assert ns["x"] == "y";
313313
assert eval("x", None, m) == "x"
314+
315+
def test_exec_encoding(self):
316+
x = {}
317+
exec(b'#!/usr/bin/python\n# vim:fileencoding=cp1250\nx = "\x9elu\x9dou\xe8k\xfd k\xf9\xf2"', x)
318+
assert x['x'] == 'žluťoučký kůň'
319+
320+
def test_exec_invalid_encoding(self):
321+
def fn():
322+
exec(b'# encoding: cp12413254\nx=1')
323+
raises(SyntaxError, fn)
324+
325+
def test_exec_ignore_decoded(self):
326+
x = {}
327+
exec('# encoding: cp12413254\nx=1', x)
328+
assert x['x'] == 1
329+
330+
def test_exec_bom(self):
331+
x = {}
332+
exec(b'\xef\xbb\xbfx = "\xe6\xa5\xbd\xe3\x81\x97\xe3\x81\x84"', x)
333+
assert x['x'] == '楽しい'
334+
335+
def test_exec_bom_invalid(self):
336+
def fn():
337+
exec(b'\xef\xbb\xbf#encoding:latin-1\nx = "\xe9\xa7\x84\xe7\x9b\xae"')
338+
raises(SyntaxError, fn)

0 commit comments

Comments
 (0)