function permute($target, $path) { foreach (range(0, 4) as $x1) { foreach (range(0, 4) as $x2) { if ($x2 == $x1) { continue; } foreach (range(0, 4) as $x3) { if (count(array_filter([$x1, $x2], function ($_) use($x3) { return $_ == $x3; }))) { continue; } foreach (range(0, 4) as $x4) { if (count(array_filter([$x1, $x2, $x3], function ($_) use($x4) { return $_ == $x4; }))) { continue; } foreach (range(0, 4) as $x5) { if (count(array_filter([$x1, $x2, $x3, $x4], function ($_) use($x5) { return $_ == $x5; }))) { continue; } $ra = new Regexp_Assemble(); $ra->insert($path[$x1])->insert($path[$x2])->insert($path[$x3])->insert($path[$x4])->insert($path[$x5]); is_deeply($ra->__path, $target, 'join: /' . join('/ /', array(join('', $path[$x1]), join('', $path[$x2]), join('', $path[$x3]), join('', $path[$x4]), join('', $path[$x5]))) . '/\\n' . $ra->dump() . ' versus ' . $ra->_dump($target) . "\n"); } } } } } }
$r = new Regexp_Assemble(); $r->add('a b'); is($r->dump(), "[a ' ' b]", 'dump path with space'); $r->insert('a', ' ', 'b', 'c', 'd'); is($r->dump(), "[a ' ' b {* c=>[c d]}]", 'dump path with space 2'); $r = new Regexp_Assemble(); $r->add('dog', 'cat'); is($r->dump(), '[{c=>[c a t] d=>[d o g]}]', 'dump node'); $r = new Regexp_Assemble(); $r->add('house', 'home'); $r->insert(); is($r->dump(), '[{* h=>[h o {m=>[m e] u=>[u s e]}]}]', 'add opt to path'); $r = new Regexp_Assemble(); $r->add('dog', 'cat'); $r->insert(); is($r->dump(), '[{* c=>[c a t] d=>[d o g]}]', 'add opt to node'); $slide = new Regexp_Assemble(); is($slide->add('schoolkids', 'acids', 'acidoids')->as_string(), '(?:ac(?:ido)?|schoolk)ids', 'schoolkids acids acidoids'); is($slide->add('schoolkids', 'acidoids')->as_string(), '(?:schoolk|acido)ids', 'schoolkids acidoids'); is($slide->add('nonschoolkids', 'nonacidoids')->as_string(), 'non(?:schoolk|acido)ids', 'nonschoolkids nonacidoids'); $r = new Regexp_Assemble(); is($r->add('sing', 'singing')->as_string(), 'sing(?:ing)?', 'super slide sing singing'); $r = new Regexp_Assemble(); is($r->add('sing', 'singing', 'sling')->as_string(), 's(?:(?:ing)?|l)ing', 'super slide sing singing sling'); $r = new Regexp_Assemble(); is($r->add('sing', 'singing', 'sling', 'slinging')->as_string(), 'sl?(?:ing)?ing', 'super slide sing singing sling slinging'); $r = new Regexp_Assemble(); is($r->add('sing', 'singing', 'sling', 'slinging', 'sting', 'stinging')->as_string(), 's[lt]?(?:ing)?ing', 'super slide sing singing sling slinging sting stinging'); $r = new Regexp_Assemble(); is($r->add('sing', 'singing', 'sling', 'slinging', 'sting', 'stinging', 'string', 'stringing', 'swing', 'swinging')->as_string(), 's(?:[lw]|tr?)?(?:ing)?ing', 'super slide sing singing sling slinging sting stinging string stringing swing swinging'); $re = new Regexp_Assemble(['flags' => 'i']);