Skip to content

Commit 930211c

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 6f622c8 + c79bfd3 commit 930211c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

bindings/python/ast.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ void bind_ast(py::module_ &m) {
362362
py::class_<kore_string_pattern, std::shared_ptr<kore_string_pattern>>(
363363
ast, "StringPattern", pattern_base)
364364
.def(py::init(&kore_string_pattern::create))
365-
.def_property_readonly("contents", &kore_string_pattern::get_contents);
365+
.def_property_readonly("contents", [](kore_string_pattern &pattern) {
366+
return py::bytes(pattern.get_contents());
367+
});
366368
}
367369

368370
void bind_parser(py::module_ &mod) {

test/python/test_patterns.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,19 @@ def test_composite(self):
3636
def test_string(self):
3737
pat = kllvm.ast.StringPattern("abc")
3838
self.assertEqual(str(pat), '"abc"')
39-
self.assertEqual(pat.contents, "abc")
39+
self.assertEqual(pat.contents.decode('raw_unicode_escape'), "abc")
40+
41+
def test_string_escape(self):
42+
value_encoded = r'\t\n\r\f\\\"'.encode('raw_unicode_escape')
43+
pat = kllvm.ast.StringPattern(value_encoded)
44+
self.assertEqual(pat.contents, value_encoded)
45+
self.assertEqual(value_encoded.decode('raw_unicode_escape'), r'\t\n\r\f\\\"')
46+
47+
def test_string_unicode(self):
48+
value_encoded = r'\u03b1'.encode('raw_unicode_escape')
49+
pat = kllvm.ast.StringPattern(value_encoded)
50+
self.assertEqual(pat.contents, value_encoded)
51+
self.assertEqual(value_encoded.decode('raw_unicode_escape'), r'α')
4052

4153
def test_variable(self):
4254
pat = kllvm.ast.VariablePattern("A", kllvm.ast.CompositeSort("S"))

0 commit comments

Comments
 (0)