@@ -49,11 +49,11 @@ private static bool ShouldAddSpace(char lastChar, char currentChar)
4949 return false ;
5050 }
5151
52- public static readonly Func < string , string > Convert = name =>
53- {
54- if ( name . Contains ( "__" ) )
55- return ExampleTitle ( name ) ;
52+ public static readonly Func < string , string > Convert = name => {
53+ return name . Contains ( "__" ) ? ExampleTitle ( name ) : ConvertNonExample ( name ) ;
54+ } ;
5655
56+ private static readonly Func < string , string > ConvertNonExample = name => {
5757 if ( name . Contains ( "_" ) )
5858 return FromUnderscoreSeparatedWords ( name ) ;
5959
@@ -62,11 +62,16 @@ private static bool ShouldAddSpace(char lastChar, char currentChar)
6262
6363 private static string ExampleTitle ( string name )
6464 {
65- name = Regex . Replace ( name , "__([a-zA-Z]+)__" , " <$1> " ) ;
65+ // Compare contains("__") with a regex match
66+ string newName = Regex . Replace ( name , "__([a-zA-Z][a-zA-Z0-9]*)__" , " <$1> " ) ;
67+
68+ if ( newName == name ) {
69+ throw new ArgumentException ( "Illegal example title in name '" + name + "'!" ) ;
70+ }
6671
6772 // for when there are two consequetive example placeholders in the word; e.g. Given__one____two__parameters
68- name = name . Replace ( " " , " " ) ;
69- return Convert ( name ) . Trim ( ) ;
73+ newName = newName . Replace ( " " , " " ) ;
74+ return Convert ( newName ) . Trim ( ) ;
7075 }
7176 }
7277}
0 commit comments