@@ -137,19 +137,32 @@ public void SimpleTransition()
137137 }
138138
139139 [ Fact ]
140- public void SimpleTransitionUML ( )
140+ public void SimpleTransitionWithEscaping ( )
141141 {
142- var expected = Prefix ( Style . UML ) + Box ( Style . UML , "A" ) + Box ( Style . UML , "B" ) + Line ( "A" , "B" , "X" ) + suffix ;
142+ var state1 = "\\ state \" 1\" " ;
143+ var state2 = "\\ state \" 2\" " ;
144+ var trigger1 = "\\ trigger \" 1\" " ;
143145
144- var sm = new StateMachine < State , Trigger > ( State . A ) ;
146+ string suffix = Environment . NewLine
147+ + $ " init [label=\" \" , shape=point];" + Environment . NewLine
148+ + $ " init -> \" { EscapeLabel ( state1 ) } \" [style = \" solid\" ]" + Environment . NewLine
149+ + "}" ;
145150
146- sm . Configure ( State . A )
147- . Permit ( Trigger . X , State . B ) ;
151+ var expected =
152+ Prefix ( Style . UML ) +
153+ Box ( Style . UML , EscapeLabel ( state1 ) ) +
154+ Box ( Style . UML , EscapeLabel ( state2 ) ) +
155+ Line ( EscapeLabel ( state1 ) , EscapeLabel ( state2 ) , EscapeLabel ( trigger1 ) ) + suffix ;
156+
157+ var sm = new StateMachine < string , string > ( state1 ) ;
158+
159+ sm . Configure ( state1 )
160+ . Permit ( trigger1 , state2 ) ;
148161
149162 string dotGraph = UmlDotGraph . Format ( sm . GetInfo ( ) ) ;
150163
151164#if WRITE_DOTS_TO_FOLDER
152- System . IO . File . WriteAllText ( DestinationFolder + "SimpleTransitionUML .dot" , dotGraph ) ;
165+ System . IO . File . WriteAllText ( DestinationFolder + "SimpleTransitionWithEscaping .dot" , dotGraph ) ;
153166#endif
154167
155168 Assert . Equal ( expected , dotGraph ) ;
@@ -445,42 +458,46 @@ public void OnEntryWithTriggerParameter()
445458 [ Fact ]
446459 public void SpacedUmlWithSubstate ( )
447460 {
448- string StateA = "State A" ;
449- string StateB = "State B" ;
450- string StateC = "State C" ;
451- string StateD = "State D" ;
452- string TriggerX = "Trigger X" ;
453- string TriggerY = "Trigger Y" ;
461+ string StateA = "State \" A\" " ;
462+ string StateB = "State \" B\" " ;
463+ string StateC = "State \" C\" " ;
464+ string StateD = "State \" D\" " ;
465+ string TriggerX = "Trigger \" X\" " ;
466+ string TriggerY = "Trigger \" Y\" " ;
467+ string EnterA = "Enter \" A\" " ;
468+ string EnterD = "Enter \" D\" " ;
469+ string ExitA = "Exit \" A\" " ;
454470
455471 var expected = Prefix ( Style . UML )
456- + Subgraph ( Style . UML , StateD , $ "{ StateD } \\ n----------\\ nentry / Enter D",
457- Box ( Style . UML , StateB )
458- + Box ( Style . UML , StateC ) )
459- + Box ( Style . UML , StateA , new List < string > { "Enter A" } , new List < string > { "Exit A" } )
460- + Line ( StateA , StateB , TriggerX ) + Line ( StateA , StateC , TriggerY )
472+ + Subgraph ( Style . UML , EscapeLabel ( StateD ) , $ "{ EscapeLabel ( StateD ) } \\ n----------\\ nentry / { EscapeLabel ( EnterD ) } ",
473+ Box ( Style . UML , EscapeLabel ( StateB ) )
474+ + Box ( Style . UML , EscapeLabel ( StateC ) ) )
475+ + Box ( Style . UML , EscapeLabel ( StateA ) , new List < string > { EscapeLabel ( EnterA ) } , new List < string > { EscapeLabel ( ExitA ) } )
476+ + Line ( EscapeLabel ( StateA ) , EscapeLabel ( StateB ) , EscapeLabel ( TriggerX ) )
477+ + Line ( EscapeLabel ( StateA ) , EscapeLabel ( StateC ) , EscapeLabel ( TriggerY ) )
461478 + Environment . NewLine
462479 + $ " init [label=\" \" , shape=point];" + Environment . NewLine
463- + $ " init -> \" { StateA } \" [style = \" solid\" ]" + Environment . NewLine
480+ + $ " init -> \" { EscapeLabel ( StateA ) } \" [style = \" solid\" ]" + Environment . NewLine
464481 + "}" ;
465482
466- var sm = new StateMachine < string , string > ( "State A" ) ;
483+ var sm = new StateMachine < string , string > ( StateA ) ;
467484
468485 sm . Configure ( StateA )
469486 . Permit ( TriggerX , StateB )
470487 . Permit ( TriggerY , StateC )
471- . OnEntry ( TestEntryAction , "Enter A" )
472- . OnExit ( TestEntryAction , "Exit A" ) ;
488+ . OnEntry ( TestEntryAction , EnterA )
489+ . OnExit ( TestEntryAction , ExitA ) ;
473490
474491 sm . Configure ( StateB )
475492 . SubstateOf ( StateD ) ;
476493 sm . Configure ( StateC )
477494 . SubstateOf ( StateD ) ;
478495 sm . Configure ( StateD )
479- . OnEntry ( TestEntryAction , "Enter D" ) ;
496+ . OnEntry ( TestEntryAction , EnterD ) ;
480497
481498 string dotGraph = UmlDotGraph . Format ( sm . GetInfo ( ) ) ;
482499#if WRITE_DOTS_TO_FOLDER
483- System . IO . File . WriteAllText ( DestinationFolder + "UmlWithSubstate .dot" , dotGraph ) ;
500+ System . IO . File . WriteAllText ( DestinationFolder + "SpacedUmlWithSubstate .dot" , dotGraph ) ;
484501#endif
485502
486503 Assert . Equal ( expected , dotGraph ) ;
@@ -716,5 +733,6 @@ public void Reentrant_Transition_Shows_Entry_Action_When_Action_Is_Configured_Wi
716733 private void TestEntryAction ( ) { }
717734 private void TestEntryActionString ( string val ) { }
718735 private State DestinationSelector ( ) { return State . A ; }
736+ private static string EscapeLabel ( string label ) { return label . Replace ( "\\ " , "\\ \\ " ) . Replace ( "\" " , "\\ \" " ) ; }
719737 }
720738}
0 commit comments