File tree 1 file changed +22
-0
lines changed 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { expect } from "chai" ;
2
+ import defaultParser , { Node , TextNode } from "../src/index" ;
3
+
4
+ describe ( "bbcode-ast tests" , ( ) => {
5
+ it ( "Should parse tag-free text" , ( ) => {
6
+ const parsed = defaultParser . parse ( "Hello world!" )
7
+ expect ( parsed . children . length ) . to . equal ( 1 ) ;
8
+ expect ( parsed . children [ 0 ] . name ) . to . equal ( "TextNode" ) ;
9
+ expect ( ( parsed . children [ 0 ] as TextNode ) . text ) . to . equal ( "Hello world!" ) ;
10
+ expect ( parsed . toString ( ) ) . to . equal ( "Hello world!" ) ;
11
+ } )
12
+
13
+ it ( "Should parse simple tag" , ( ) => {
14
+ const parsed = defaultParser . parse ( "[b]Hello world![/b]" )
15
+ expect ( parsed . children . length ) . to . equal ( 1 ) ;
16
+ expect ( parsed . children [ 0 ] . name ) . to . equal ( "b" ) ;
17
+ expect ( ( parsed . children [ 0 ] as Node ) . children . length ) . to . equal ( 1 ) ;
18
+ expect ( ( parsed . children [ 0 ] as Node ) . children [ 0 ] . name ) . to . equal ( "TextNode" ) ;
19
+ expect ( ( ( parsed . children [ 0 ] as Node ) . children [ 0 ] as TextNode ) . text ) . to . equal ( "Hello world!" ) ;
20
+ expect ( parsed . toString ( ) ) . to . equal ( "[b]Hello world![/b]" ) ;
21
+ } )
22
+ } )
You can’t perform that action at this time.
0 commit comments