Created
January 8, 2011 09:05
-
-
Save worr/770704 to your computer and use it in GitHub Desktop.
(almost) matches well-formed XML
This file contains hidden or 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
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use 5.012; | |
| use Test::More tests => 18; | |
| my @success = ("<content><test>testing</test><test>woo</test></content>", | |
| "<content></content>", | |
| "<content><test>words<bear>monkey</bear></test></content>", | |
| "<sup bear=\"mother\"><test><apple monkey=\"carbeurator\"></apple></test></sup>", | |
| "<sup /><test><sup /></test>", | |
| "<sup />", | |
| "<sup test=\"hi\" />", | |
| "<test><sup test=\"hi\" /></test>"); | |
| my @fail = ("<content><dicks><woo></dicks></content>", | |
| "<content>", | |
| "<content woo></content>", | |
| "<content woo=test></content>", | |
| "<test><content></test></content>", | |
| "<sup /></sup>", | |
| "<sup /><sup>", | |
| "<test></test></test>", | |
| "<content></content><test></test>", | |
| "<test><sup></test>"); | |
| my $regexp = qr{^(<(\w+?)(?: \w+=".+?")*(?(?=\s/>)\s/>(?1)?|>[^<>]*(?>(?1)*</\2>))$}; | |
| foreach my $input (@success) { | |
| like($input, $regexp); | |
| } | |
| foreach my $input (@fail) { | |
| unlike($input, $regexp); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment