Page 5 of 6
Re: CryoBB - Create your own Bulletin Board
Posted: Wed Dec 22, 2010 7:38 pm
by Jonah Bron
josh wrote:First I'd say you'd need to define the expected inputs & outputs you want to see in this mode, with enough scenarios to show how it should work in all situations.
Er, which mode?
josh wrote:Another would be what to do if I close a tag I never opened?
Probably close either at the end of the parent, or the end of the string.
Re: CryoBB - Create your own Bulletin Board
Posted: Wed Dec 22, 2010 7:59 pm
by s.dot
If a tag is never opened or a tag is never closed, the regexp will not detect it and will just leave it alone.
Wondering why correct the invalid nesting instead of just parsing it?
Edit| I mean, if a parser could be wrote to correct all invalid nests and open and close tags, then that would be beyond the scope of amazing. But seems like a rather complex chore.
Re: CryoBB - Create your own Bulletin Board
Posted: Wed Dec 22, 2010 8:20 pm
by josh
If you can define expected inputs & outputs, I think I could wing whatever is specified. However IMO the list of specs could become rather large if we try and do too much, I think its definitely worth considering.
Perhaps before we do that, we could do one that outputs invalid XHTML (and keep that as a separate mode as well)? That will provide some value to some users, and help us better gauge the complexity. Or not?
Re: CryoBB - Create your own Bulletin Board
Posted: Wed Dec 22, 2010 8:50 pm
by s.dot
OK, I think there are several "modes" here that have been discussed (from my understanding)
1) As it currently is
2) One that parses all tags, even if they're improperly nested, producing invalid xhtml
3) One that produces valid xhtml
4) One that fixes invalid nesting and produces valid xhtml
Have I got it straight?
1 and 2 would be great. 3 would be awesome, 4 would be asking too much (though definitely cool)
And if 3 or 4 were to be done, wouldn't that replace 1 and 2? (I mean why have 1 and 2, if 3-4 could do the same thing but with valid output)
Re: CryoBB - Create your own Bulletin Board
Posted: Wed Dec 22, 2010 9:06 pm
by josh
1 & 3 sound the same.
Re: CryoBB - Create your own Bulletin Board
Posted: Wed Dec 22, 2010 10:27 pm
by Jonah Bron
Lets start with adding number 2. We already have 1/3, all we have to do is break it out into a separate object, then create a drop-in replacement that uses method 2.
Re: CryoBB - Create your own Bulletin Board
Posted: Wed Dec 22, 2010 11:13 pm
by josh
Here's a unit test:
Code: Select all
// function testShouldGenerateInvalidXHTMLFromInvalidNesting()
// {
// $base = new CryoBB_Base();
// $base->addTag($this->tagBold());
// $base->addTag($this->tagItalics());
//
// $actual = $base->make('[b]foo[i]bar[/b][/i]');
// $this->assertEqual($actual, '<strong>foo<i>bar</strong></i>', 'Should generate invalid XHTML from invalid nesting');
// }
I checked it in, uncomment first to experience TDD
Edit: just do something after uncommenting to "flag" which mode it is in.
Re: CryoBB - Create your own Bulletin Board
Posted: Thu Dec 23, 2010 12:52 pm
by Jonah Bron
I'll start on separating out the matching object sometime today, probably this morning.
Re: CryoBB - Create your own Bulletin Board
Posted: Thu Dec 23, 2010 2:39 pm
by Jonah Bron
Done. Feedback?
Re: CryoBB - Create your own Bulletin Board
Posted: Thu Dec 23, 2010 9:43 pm
by josh
Good work. I like how you moved the regex in a text file. You probably did too much for implementing the 'non strict' one, adding the constant and all when the feature doesn't yet exist

But a non-TDD programmer would probably call me silly (and I'd think the same of them)
Edit bloops you let a comment go out of date. That's why I hate comments
Code: Select all
/**
* Matches bb code tags and their contents
*
* Recursively matches bb code tags and their contents based on the regexp
* in property $matchRegexp.
Re: CryoBB - Create your own Bulletin Board
Posted: Thu Dec 23, 2010 10:42 pm
by Jonah Bron
josh wrote:Edit bloops you let a comment go out of date. That's why I hate comments

Funny thing, I accidentally made a few of the changes in "unstable", and remembered afterward. That was one of them

Re: CryoBB - Create your own Bulletin Board
Posted: Thu Dec 23, 2010 11:10 pm
by josh
Jonah Bron wrote:josh wrote:Edit bloops you let a comment go out of date. That's why I hate comments

Funny thing, I accidentally made a few of the changes in "unstable", and remembered afterward. That was one of them

That's why I hate branches

Re: CryoBB - Create your own Bulletin Board
Posted: Thu Dec 23, 2010 11:28 pm
by Jonah Bron
josh wrote:That's why I hate branches

Then I don't think you'd like Git

Re: CryoBB - Create your own Bulletin Board
Posted: Tue Jan 04, 2011 4:47 pm
by josh
The way I'd recommend tackling this new strategy is to first get the old strategy under unit test. Right now its tested indirectly thru "base.php".
(@Jonah & Scott)
The way I understand this currently works is the current strategy finds "positions" of matches. It then loops thru matches, replacing with replacements. Each time it does this it factors in the difference of the length of the old & new text, so that it can update the positions. (the difference in length between the matched text & the text to be substituted is subtracted from the positions of all remaining matches)
We have no unit tests that show that these sub-systems find the right positions, but we do show that the thing as a whole works, in our tests.
I'd find it really easy to do this feature, if we first had some tests that shows the inputs & outputs for finding positions with the current strategy. From there I could duplicate the tests, and modify the expected positions as per the new algorithm, from there I could duplicate & change the existing implementation and modify it to do matching differently until the tests pass, then we could refactor. I don't mean to rant about tests, just saying how I'd keep the ball rolling if I were familiar enough with the code, or if it had enough tests for me to do this in this area.
If you guys can get at least 1 test showing an input string, and the output array of positions, I could probably take it from there...
Re: CryoBB - Create your own Bulletin Board
Posted: Fri Jan 07, 2011 1:48 pm
by Jonah Bron
josh wrote:(@Jonah & Scott)
The way I understand this currently works is the current strategy finds "positions" of matches. It then loops thru matches, replacing with replacements. Each time it does this it factors in the difference of the length of the old & new text, so that it can update the positions. (the difference in length between the matched text & the text to be substituted is subtracted from the positions of all remaining matches)
That's exactly right.
josh wrote:I'd find it really easy to do this feature, if we first had some tests that shows the inputs & outputs for finding positions with the current strategy. From there I could duplicate the tests, and modify the expected positions as per the new algorithm, from there I could duplicate & change the existing implementation and modify it to do matching differently until the tests pass, then we could refactor. I don't mean to rant about tests, just saying how I'd keep the ball rolling if I were familiar enough with the code, or if it had enough tests for me to do this in this area.
If you guys can get at least 1 test showing an input string, and the output array of positions, I could probably take it from there...
Yes, that needs to be done. BTW, as you can see I'm back now. I'm still pretty wiped out, so I won't be able to do anything today.