'use strict';

var stemmer, Retext, visit, assert, tree, otherWords, otherStems;

stemmer = require('..');
Retext = require('retext');
visit = require('retext-visit');
assert = require('assert');

tree = new Retext()
    .use(visit)
    .use(stemmer)
    .parse('A simple, english, sentence');

otherWords = ['An', 'easy', 'normal', 'paragraph'];
otherStems = ['An', 'easi', 'normal', 'paragraph'];

describe('porterStemmer()', function () {
    it('should be of type `function`', function () {
        assert(typeof stemmer === 'function');
    });

    it('should export an attach method of type `function`', function () {
        assert(typeof stemmer.attach === 'function');
    });

    it('should export a porterStemmer method of type `function`',
        function () {
            assert(typeof stemmer.porterStemmer === 'function');
        }
    );

    it('should stem each `WordNode`', function () {
        tree.visitType(tree.WORD_NODE, function (wordNode) {
            assert('stem' in wordNode.data);
        });
    });

    it('should set each stem to `null` when a WordNode (no longer?) has ' +
        'a value', function () {
            tree.visitType(tree.WORD_NODE, function (wordNode) {
                wordNode[0].fromString();
                assert(wordNode.data.stem === null);
            });
    });

    it('should automatically re-stem `WordNode`s when their values change',
        function () {
            var iterator = -1;
            tree.visitType(tree.WORD_NODE, function (wordNode) {
                wordNode[0].fromString(otherWords[++iterator]);
                assert(wordNode.data.stem === otherStems[iterator]);
            });
    });
});

@@ -24,37 +24,72 @@
 mer,
- Retex
+%0A    conten
 t,
+%0A   
  visit,
- assert, tree,
+%0A    Retext,%0A    assert,%0A    retext,%0A   
  oth
@@ -96,16 +96,20 @@
 erWords,
+%0A   
  otherSt
@@ -114,16 +114,49 @@
 Stems;%0A%0A
+/**%0A * Module dependencies.%0A */%0A%0A
 stemmer 
@@ -233,16 +233,53 @@
 isit');%0A
+content = require('retext-content');%0A
 assert =
@@ -299,20 +299,42 @@
 ert');%0A%0A
-tree
+/**%0A * Retext.%0A */%0A%0Aretext
  = new R
@@ -370,59 +370,58 @@
 use(
-stemmer)%0A    .parse('A simple, english, sentence');
+content)%0A    .use(stemmer);%0A%0A/**%0A * Constants.%0A */
 %0A%0Aot
@@ -523,16 +523,35 @@
 aph'%5D;%0A%0A
+/**%0A * Tests.%0A */%0A%0A
 describe
@@ -602,23 +602,17 @@
 ould be 
-of type
+a
  %60functi
@@ -716,40 +716,23 @@
  an 
+%60
 attach
+%60
  method
- of type %60function%60
 ', f
@@ -815,77 +815,105 @@
     
-it('should export a porterStemmer method of type %60function%60',%0A       
+retext.parse('A simple, english, sentence', function (err, tree) %7B%0A        it('should not throw',
  fun
@@ -911,32 +911,36 @@
 row', function (
+done
 ) %7B%0A            
@@ -943,58 +943,16 @@
     
-assert(typeof stemmer.porterStemmer === 'function'
+done(err
 );%0A 
@@ -963,17 +963,16 @@
    %7D
+);%0A
 %0A    
-);%0A%0A
     
@@ -982,20 +982,22 @@
 'should 
+%60
 stem
+%60
  each %60W
@@ -1013,32 +1013,36 @@
 , function () %7B%0A
+    
         tree.vis
@@ -1094,24 +1094,28 @@
             
+    
 assert('stem
@@ -1139,32 +1139,36 @@
 a);%0A        
+    
 %7D);%0A    
 %7D);%0A%0A    it(
@@ -1147,37 +1147,45 @@
         %7D);%0A    
+    
 %7D);%0A%0A
+    
     it('should s
@@ -1239,12 +1239,8 @@
 er?)
- has
  ' +
@@ -1248,17 +1248,25 @@
         
-'
+    'has 
 a value'
@@ -1273,32 +1273,36 @@
 , function () %7B%0A
+    
             tree
@@ -1362,32 +1362,36 @@
             
+    
 wordNode
 %5B0%5D.fromStri
@@ -1382,26 +1382,31 @@
 Node
-%5B0%5D.fromString();%0A
+.removeContent();%0A%0A    
     
@@ -1462,32 +1462,36 @@
             
+    
 %7D);%0A    
 %7D);%0A%0A    it(
@@ -1474,29 +1474,50 @@
     %7D);%0A    
-%7D);%0A%0A
+        %7D%0A        );%0A%0A    
     it('shou
@@ -1571,16 +1571,33 @@
  values 
+' +%0A            '
 change',
@@ -1597,16 +1597,20 @@
 hange',%0A
+    
         
@@ -1639,27 +1639,57 @@
     
+    
 var i
-terator
+ndex;%0A%0A                index
  = -1;%0A
+%0A    
     
@@ -1765,24 +1765,28 @@
         
+    
 wordNode
 %5B0%5D.from
@@ -1781,22 +1781,23 @@
 Node
-%5B0%5D.fromString
+.replaceContent
 (oth
@@ -1807,27 +1807,29 @@
 ords%5B++i
-terator%5D);%0A
+ndex%5D);%0A%0A    
         
@@ -1882,19 +1882,20 @@
 ms%5Bi
-terator%5D);%0A
+ndex%5D);%0A    
     
@@ -1902,24 +1902,49 @@
         %7D);%0A
+            %7D%0A        );%0A
     %7D);%0A%7D);%0A

Refactor spec for retext@0.2.0