forked from Perl/perl5
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add valid_identifier_{pve,pvn,sv} API functions
These functions test whether a given string would be considered by the Perl parser to be a valid identifier. Three variants are provided: one taking a string start/end pair, one a string start/length pair, and one looking at the string contained in an SV.
- Loading branch information
Showing
9 changed files
with
184 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ use strict; | |
use warnings; | ||
use Carp; | ||
|
||
our $VERSION = '1.39'; | ||
our $VERSION = '1.40'; | ||
|
||
require XSLoader; | ||
|
||
|
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,43 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use open ':std', ':encoding(UTF-8)'; | ||
use Test::More; | ||
|
||
use_ok('XS::APItest'); | ||
|
||
# These should all be valid | ||
foreach my $id (qw( abc ab_cd _abc x123 )) { | ||
ok(valid_identifier($id), "'$id' is valid identifier"); | ||
} | ||
|
||
# These should all not be | ||
foreach my $id (qw( ab-cd 123 abc() ), "ab cd") { | ||
ok(!valid_identifier($id), "'$id' is not valid identifier"); | ||
} | ||
|
||
# Now for some UTF-8 tests | ||
{ | ||
use utf8; | ||
|
||
foreach my $id (qw( café sandviĉon )) { | ||
ok(valid_identifier($id), "'$id' is valid UTF-8 identifier"); | ||
} | ||
|
||
# en-dash | ||
ok(!valid_identifier("ab–cd"), "'ab–cd' is not valid UTF-8 identifier"); | ||
} | ||
|
||
# objects with "" overloading still work | ||
{ | ||
package WithStringify { | ||
use overload '""' => sub { return "an_identifier"; }; | ||
sub new { bless [], shift; } | ||
} | ||
|
||
ok(valid_identifier(WithStringify->new), 'Object with stringify overload can be valid identifier'); | ||
} | ||
|
||
done_testing; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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