New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Perl 6 samples #900
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,97 @@ | ||
use v6; | ||
|
||
use Test; | ||
|
||
=begin pod | ||
|
||
Test handling of -I. | ||
|
||
Multiple C<-I> switches are supposed to | ||
prepend left-to-right: | ||
|
||
-Ifoo -Ibar | ||
|
||
should make C<@*INC> look like: | ||
|
||
foo | ||
bar | ||
... | ||
|
||
Duplication of directories on the command line is mirrored | ||
in the C<@*INC> variable, so C<pugs -Ilib -Ilib> will have B<two> | ||
entries C<lib/> in C<@*INC>. | ||
|
||
=end pod | ||
|
||
# L<S19/Reference/"Prepend directories to"> | ||
|
||
my $fragment = '-e "@*INC.perl.say"'; | ||
|
||
my @tests = ( | ||
'foo', | ||
'foo$bar', | ||
'foo bar$baz', | ||
'foo$foo', | ||
); | ||
|
||
plan @tests*2; | ||
|
||
diag "Running under $*OS"; | ||
|
||
my ($pugs,$redir) = ($*EXECUTABLE_NAME, ">"); | ||
|
||
if $*OS eq any <MSWin32 mingw msys cygwin> { | ||
$pugs = 'pugs.exe'; | ||
$redir = '>'; | ||
}; | ||
|
||
sub nonce () { return (".{$*PID}." ~ (1..1000).pick) } | ||
|
||
sub run_pugs ($c) { | ||
my $tempfile = "temp-ex-output" ~ nonce; | ||
my $command = "$pugs $c $redir $tempfile"; | ||
diag $command; | ||
run $command; | ||
my $res = slurp $tempfile; | ||
unlink $tempfile; | ||
return $res; | ||
} | ||
|
||
for @tests -> $t { | ||
my @dirs = split('$',$t); | ||
my $command; | ||
# This should be smarter about quoting | ||
# (currently, this should work for WinNT and Unix shells) | ||
$command = join " ", map { qq["-I$_"] }, @dirs; | ||
my $got = run_pugs( $command ~ " $fragment" ); | ||
$got .= chomp; | ||
|
||
if (substr($got,0,1) ~~ "[") { | ||
# Convert from arrayref to array | ||
$got = substr($got, 1, -1); | ||
}; | ||
|
||
my @got = EVAL $got; | ||
@got = @got[ 0..@dirs-1 ]; | ||
my @expected = @dirs; | ||
|
||
is @got, @expected, "'" ~ @dirs ~ "' works"; | ||
|
||
$command = join " ", map { qq[-I "$_"] }, @dirs; | ||
$got = run_pugs( $command ~ " $fragment" ); | ||
|
||
$got .= chomp; | ||
if (substr($got,0,1) ~~ "[") { | ||
# Convert from arrayref to array | ||
$got = substr($got, 1, -1); | ||
}; | ||
|
||
@got = EVAL $got; | ||
@got = @got[ 0..@dirs-1 ]; | ||
@expected = @dirs; | ||
|
||
is @got, @expected, "'" ~ @dirs ~ "' works (with a space delimiting -I)"; | ||
} | ||
|
||
|
||
# vim: ft=perl6 |
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,223 @@ | ||
use v6; | ||
BEGIN { @*INC.push('lib') }; | ||
|
||
use JSON::Tiny::Grammar; | ||
use Test; | ||
|
||
my @t = | ||
'{}', | ||
'{ }', | ||
' { } ', | ||
'{ "a" : "b" }', | ||
'{ "a" : null }', | ||
'{ "a" : true }', | ||
'{ "a" : false }', | ||
'{ "a" : { } }', | ||
'[]', | ||
'[ ]', | ||
' [ ] ', | ||
# stolen from JSON::XS, 18_json_checker.t, and adapted a bit | ||
Q<<[ | ||
"JSON Test Pattern pass1", | ||
{"object with 1 member":["array with 1 element"]}, | ||
{}, | ||
[] | ||
]>>, | ||
Q<<[1]>>, | ||
Q<<[true]>>, | ||
Q<<[-42]>>, | ||
Q<<[-42,true,false,null]>>, | ||
Q<<{ "integer": 1234567890 }>>, | ||
Q<<{ "real": -9876.543210 }>>, | ||
Q<<{ "e": 0.123456789e-12 }>>, | ||
Q<<{ "E": 1.234567890E+34 }>>, | ||
Q<<{ "": 23456789012E66 }>>, | ||
Q<<{ "zero": 0 }>>, | ||
Q<<{ "one": 1 }>>, | ||
Q<<{ "space": " " }>>, | ||
Q<<{ "quote": "\""}>>, | ||
Q<<{ "backslash": "\\"}>>, | ||
Q<<{ "controls": "\b\f\n\r\t"}>>, | ||
Q<<{ "slash": "/ & \/"}>>, | ||
Q<<{ "alpha": "abcdefghijklmnopqrstuvwyz"}>>, | ||
Q<<{ "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ"}>>, | ||
Q<<{ "digit": "0123456789"}>>, | ||
Q<<{ "0123456789": "digit"}>>, | ||
Q<<{"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?"}>>, | ||
Q<<{"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"}>>, | ||
Q<<{"true": true}>>, | ||
Q<<{"false": false}>>, | ||
Q<<{"null": null}>>, | ||
Q<<{"array":[ ]}>>, | ||
Q<<{"object":{ }}>>, | ||
Q<<{"address": "50 St. James Street"}>>, | ||
Q<<{"url": "http://www.JSON.org/"}>>, | ||
Q<<{"comment": "// /* <!-- --"}>>, | ||
Q<<{"# -- --> */": " "}>>, | ||
Q<<{ " s p a c e d " :[1,2 , 3 | ||
|
||
, | ||
|
||
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7]}>>, | ||
|
||
Q<<{"jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}"}>>, | ||
Q<<{"quotes": "" \u0022 %22 0x22 034 ""}>>, | ||
Q<<{ "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" | ||
: "A key can be any string" | ||
}>>, | ||
Q<<[ 0.5 ,98.6 | ||
, | ||
99.44 | ||
, | ||
|
||
1066, | ||
1e1, | ||
0.1e1 | ||
]>>, | ||
Q<<[1e-1]>>, | ||
Q<<[1e00,2e+00,2e-00,"rosebud"]>>, | ||
Q<<[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]>>, | ||
Q<<{ | ||
"JSON Test Pattern pass3": { | ||
"The outermost value": "must be an object or array.", | ||
"In this test": "It is an object." | ||
} | ||
} | ||
>>, | ||
# from http://www.json.org/example.html | ||
Q<<{ | ||
"glossary": { | ||
"title": "example glossary", | ||
"GlossDiv": { | ||
"title": "S", | ||
"GlossList": { | ||
"GlossEntry": { | ||
"ID": "SGML", | ||
"SortAs": "SGML", | ||
"GlossTerm": "Standard Generalized Markup Language", | ||
"Acronym": "SGML", | ||
"Abbrev": "ISO 8879:1986", | ||
"GlossDef": { | ||
"para": "A meta-markup language, used to create markup languages such as DocBook.", | ||
"GlossSeeAlso": ["GML", "XML"] | ||
}, | ||
"GlossSee": "markup" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
>>, | ||
Q<<{"menu": { | ||
"id": "file", | ||
"value": "File", | ||
"popup": { | ||
"menuitem": [ | ||
{"value": "New", "onclick": "CreateNewDoc()"}, | ||
{"value": "Open", "onclick": "OpenDoc()"}, | ||
{"value": "Close", "onclick": "CloseDoc()"} | ||
] | ||
} | ||
}}>>, | ||
Q<<{"widget": { | ||
"debug": "on", | ||
"window": { | ||
"title": "Sample Konfabulator Widget", | ||
"name": "main_window", | ||
"width": 500, | ||
"height": 500 | ||
}, | ||
"image": { | ||
"src": "Images/Sun.png", | ||
"name": "sun1", | ||
"hOffset": 250, | ||
"vOffset": 250, | ||
"alignment": "center" | ||
}, | ||
"text": { | ||
"data": "Click Here", | ||
"size": 36, | ||
"style": "bold", | ||
"name": "text1", | ||
"hOffset": 250, | ||
"vOffset": 100, | ||
"alignment": "center", | ||
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" | ||
} | ||
}}>>, | ||
; | ||
|
||
my @n = | ||
'{ ', | ||
'{ 3 : 4 }', | ||
'{ 3 : tru }', # not quite true | ||
'{ "a : false }', # missing quote | ||
# stolen from JSON::XS, 18_json_checker.t | ||
Q<<"A JSON payload should be an object or array, not a string.">>, | ||
Q<<{"Extra value after close": true} "misplaced quoted value">>, | ||
Q<<{"Illegal expression": 1 + 2}>>, | ||
Q<<{"Illegal invocation": alert()}>>, | ||
Q<<{"Numbers cannot have leading zeroes": 013}>>, | ||
Q<<{"Numbers cannot be hex": 0x14}>>, | ||
Q<<["Illegal backslash escape: \x15"]>>, | ||
Q<<[\naked]>>, | ||
Q<<["Illegal backslash escape: \017"]>>, | ||
# skipped: wo don't implement no stinkin' aritifical limits. | ||
# Q<<[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]>>, | ||
Q<<{"Missing colon" null}>>, | ||
Q<<["Unclosed array">>, | ||
Q<<{"Double colon":: null}>>, | ||
Q<<{"Comma instead of colon", null}>>, | ||
Q<<["Colon instead of comma": false]>>, | ||
Q<<["Bad value", truth]>>, | ||
Q<<['single quote']>>, | ||
qq<["\ttab\tcharacter in string "]>, | ||
Q<<["line | ||
break"]>>, | ||
Q<<["line\ | ||
break"]>>, | ||
Q<<[0e]>>, | ||
Q<<{unquoted_key: "keys must be quoted"}>>, | ||
Q<<[0e+]>>, | ||
Q<<[0e+-1]>>, | ||
Q<<{"Comma instead if closing brace": true,>>, | ||
Q<<["mismatch"}>>, | ||
Q<<["extra comma",]>>, | ||
Q<<["double extra comma",,]>>, | ||
Q<<[ , "<-- missing value"]>>, | ||
Q<<["Comma after the close"],>>, | ||
Q<<["Extra close"]]>>, | ||
Q<<{"Extra comma": true,}>>, | ||
; | ||
|
||
plan (+@t) + (+@n); | ||
|
||
my $i = 0; | ||
for @t -> $t { | ||
my $desc = $t; | ||
if $desc ~~ m/\n/ { | ||
$desc .= subst(/\n.*$/, "\\n...[$i]"); | ||
} | ||
my $parsed = 0; | ||
try { | ||
JSON::Tiny::Grammar.parse($t) | ||
and $parsed = 1; | ||
} | ||
ok $parsed, "JSON string «$desc» parsed"; | ||
$i++; | ||
} | ||
|
||
for @n -> $t { | ||
my $desc = $t; | ||
if $desc ~~ m/\n/ { | ||
$desc .= subst(/\n.*$/, "\\n...[$i]"); | ||
} | ||
my $parsed = 0; | ||
try { JSON::Tiny::Grammar.parse($t) and $parsed = 1 }; | ||
nok $parsed, "NOT parsed «$desc»"; | ||
$i++; | ||
} | ||
|
||
|
||
# vim: ft=perl6 | ||
|
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,9 @@ | ||
# used in t/spec/S11-modules/nested.t | ||
|
||
BEGIN { @*INC.push('t/spec/packages') }; | ||
|
||
module A::A { | ||
use A::B; | ||
} | ||
|
||
# vim: ft=perl6 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to find a TextMate or Sublime grammar that supports Perl6? I found this one but I'm not sure if it'll work straight out of the box: https://github.com/ashgti/perl-tmbundle Also, it's missing a license.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arfon That was the one I was recommended; however, does it interfere with https://github.com/textmate/perl.tmbundle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that will conflict as they're defined with the same name. How well does the standard Perl syntax highlighter do on Perl6 files?
It might be worth trying out https://github.com/textmate/perl.tmbundle on https://lightshow.githubapp.com
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it would do very well; Perl 6 is a very different beast from Perl 5. I know that the pygments and vim highlighters for Perl 5 don't do a very good job with it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we ask https://github.com/ashgti/perl-tmbundle if they can change their scope name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'm going to merge this without a
tm_scope
at this stage. We can one in later once this naming issue is resolved.