Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Support passing Bufs to Python
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env perl6 | ||
|
|
||
| use v6; | ||
| use Test; | ||
| use Inline::Python; | ||
|
|
||
| plan 4; | ||
|
|
||
| my $py = Inline::Python.new(); | ||
| $py.run(q[ | ||
| def identity(a): | ||
| return a | ||
| ]); | ||
|
|
||
| class Foo { | ||
| } | ||
| # , 24, 2.4.Num, [1, 2], { a => 1, b => 2}, Any, Foo.new | ||
| for ('abcö', Buf.new('äbc'.encode('latin-1'))) -> $obj { | ||
| is_deeply $py.call('__main__', 'identity', $obj), $obj, "Can round-trip " ~ $obj.^name; | ||
| } | ||
|
|
||
| $py.run(q/ | ||
| # coding=utf-8 | ||
| def check_utf8(str): | ||
| return str == u'Töst' | ||
| /); | ||
|
|
||
| ok($py.call('__main__', 'check_utf8', 'Töst'), 'UTF-8 string recognized in Python'); | ||
|
|
||
| $py.run(q/ | ||
| # coding=utf-8 | ||
| def check_latin1(str): | ||
| return str.decode('latin-1') == u'Töst'; | ||
| /); | ||
|
|
||
| ok($py.call('__main__', 'check_latin1', 'Töst'.encode('latin-1')), 'latin-1 works in Python'); | ||
|
|
||
| $py.run(q/ | ||
| def is_two_point_five(a): | ||
| return a == 2.5; | ||
| /); | ||
|
|
||
| #ok($py.call('__main__', 'is_two_point_five', Num.new(2.5))); | ||
|
|
||
| # vim: ft=perl6 |