@ -1,9 +1,7 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using UnityEngine ;
using Fungus ;
using Fungus ;
#if UNITY_5_3_OR_NEWER
#if UNITY_5_3_OR_NEWER
@ -20,7 +18,7 @@ public class TextTagParserTests
var textTagParser = new TextTagParser ( ) ;
var textTagParser = new TextTagParser ( ) ;
// Parse an example string, generate correct sequence of tags
// Parse an example string, generate correct sequence of tags
List < TextTagParser . Token > tokens = textTagParser . Tokenize ( "Words " +
List < TextTagToken > tokens = textTagParser . Tokenize ( "Words " +
"{b}bold test{/b}" +
"{b}bold test{/b}" +
"{i}italic test{/i}" +
"{i}italic test{/i}" +
"{color=red}color test{/color}" +
"{color=red}color test{/color}" +
@ -41,139 +39,139 @@ public class TextTagParserTests
"{audiostop=Sound}" ) ;
"{audiostop=Sound}" ) ;
int i = 0 ;
int i = 0 ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Words ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Words ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Words " ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Words " ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . BoldStart ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . BoldStart ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Words ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Words ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "bold test" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "bold test" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . BoldEnd ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . BoldEnd ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . ItalicStart ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . ItalicStart ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Words ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Words ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "italic test" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "italic test" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . ItalicEnd ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . ItalicEnd ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . ColorStart ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . ColorStart ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "red" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "red" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Words ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Words ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "color test" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "color test" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . ColorEnd ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . ColorEnd ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . SizeStart ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . SizeStart ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "30" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "30" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Words ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Words ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "size test" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "size test" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . SizeEnd ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . SizeEnd ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Wait ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Wait ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Wait ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Wait ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . WaitForInputNoClear ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . WaitForInputNoClear ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . WaitForInputAndClear ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . WaitForInputAndClear ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . WaitOnPunctuationStart ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . WaitOnPunctuationStart ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . WaitOnPunctuationStart ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . WaitOnPunctuationStart ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . WaitOnPunctuationEnd ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . WaitOnPunctuationEnd ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Clear ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Clear ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . SpeedStart ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . SpeedStart ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . SpeedStart ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . SpeedStart ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "60" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "60" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . SpeedEnd ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . SpeedEnd ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Exit ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Exit ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
Assert . That ( tokens [ i ] . paramList . Count = = 0 ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Message ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Message ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Message" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Message" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . VerticalPunch ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . VerticalPunch ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . HorizontalPunch ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . HorizontalPunch ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Punch ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Punch ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Flash ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Flash ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "0.5" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Audio ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Audio ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Sound" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Sound" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . AudioLoop ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . AudioLoop ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Sound" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Sound" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . AudioPause ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . AudioPause ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Sound" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Sound" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . AudioStop ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . AudioStop ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Sound" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Sound" ) ;
Assert . That ( tokens . Count = = 3 4 ) ;
Assert . That ( tokens . Count = = 3 4 ) ;
@ -185,38 +183,38 @@ public class TextTagParserTests
var textTagParser = new TextTagParser ( ) ;
var textTagParser = new TextTagParser ( ) ;
// Parse an example string, generate correct sequence of tags
// Parse an example string, generate correct sequence of tags
List < TextTagParser . Token > tokens = textTagParser . Tokenize ( "Play sound{audio=BeepSound}{w=1} Play loop{audioloop=BeepSound}{w=3} Stop{audiostop=BeepSound}" ) ;
List < TextTagToken > tokens = textTagParser . Tokenize ( "Play sound{audio=BeepSound}{w=1} Play loop{audioloop=BeepSound}{w=3} Stop{audiostop=BeepSound}" ) ;
int i = 0 ;
int i = 0 ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Words ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Words ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Play sound" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "Play sound" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Audio ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Audio ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "BeepSound" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "BeepSound" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Wait ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Wait ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "1" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "1" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Words ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Words ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = " Play loop" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = " Play loop" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . AudioLoop ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . AudioLoop ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "BeepSound" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "BeepSound" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Wait ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Wait ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "3" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "3" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . Words ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . Words ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = " Stop" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = " Stop" ) ;
i + + ;
i + + ;
Assert . That ( tokens [ i ] . type = = TextTagParser . TokenType . AudioStop ) ;
Assert . That ( tokens [ i ] . type = = TextTagToken . TokenType . AudioStop ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "BeepSound" ) ;
Assert . That ( tokens [ i ] . paramList [ 0 ] = = "BeepSound" ) ;
Assert . That ( tokens . Count = = 8 ) ;
Assert . That ( tokens . Count = = 8 ) ;