Skip to content

Commit e115a94

Browse files
committed
Enable json language injection for .feature files and reformat them.
1 parent 51f89ab commit e115a94

26 files changed

+761
-749
lines changed

backend/.editorconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ indent_size = 2
8484
indent_style = space
8585
indent_size = 4
8686

87-
[*.feature]
88-
indent_style = space
89-
indent_size = 4
90-
9187
[{*.bash,*.sh,*.zsh}]
9288
indent_style = space
9389
indent_size = 2
@@ -104,3 +100,7 @@ tab_width = 4
104100
[*.nginx]
105101
indent_style = space
106102
tab_width = 4
103+
104+
[*.feature]
105+
indent_style = space
106+
indent_size = 2

backend/Naheulbook.slnx.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static class ServiceCollectionExtensions
2929
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=F9BE8C6944C15E429D07F152F09A7A68/Text/@EntryValue">private static readonly DateTimeOffset NowUtc = new DateTimeOffset(2020, 12, 8, 10, 12, 8, TimeSpan.Zero);</s:String>
3030
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean>
3131
<s:Boolean x:Key="/Default/UserDictionary/Words/=Debilibeuk/@EntryIndexedValue">True</s:Boolean>
32+
<s:Boolean x:Key="/Default/UserDictionary/Words/=homme/@EntryIndexedValue">True</s:Boolean>
3233
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mankdebol/@EntryIndexedValue">True</s:Boolean>
3334
<s:Boolean x:Key="/Default/UserDictionary/Words/=Melkor/@EntryIndexedValue">True</s:Boolean>
3435
<s:Boolean x:Key="/Default/UserDictionary/Words/=Middlewares/@EntryIndexedValue">True</s:Boolean>

backend/tests/Naheulbook.Tests.Functional/Code/Extensions/StringExtensions.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static string ExecuteReplacement(this string str, ScenarioContext context
1919
var replacementTokens = ListReplacementTokens(str);
2020
var missingKeys = new List<string>();
2121

22-
foreach (var replacementToken in replacementTokens)
22+
foreach (var (kind, replacementToken) in replacementTokens)
2323
{
2424
try
2525
{
@@ -38,7 +38,19 @@ public static string ExecuteReplacement(this string str, ScenarioContext context
3838
break;
3939
}
4040

41-
str = str.Replace($"${{{replacementToken}}}", replacementValue);
41+
switch (kind)
42+
{
43+
case ReplacementKind.None:
44+
break;
45+
case ReplacementKind.Raw:
46+
str = str.Replace($"${{{replacementToken}}}", replacementValue);
47+
break;
48+
case ReplacementKind.Quoted:
49+
str = str.Replace($"\"!{{{replacementToken}}}\"", replacementValue);
50+
break;
51+
default:
52+
throw new ArgumentOutOfRangeException();
53+
}
4254
}
4355
catch (ReplacementKeyNotfoundException ex)
4456
{
@@ -137,36 +149,49 @@ private static bool IsArrayAccessor(string propertyName)
137149
return propertyName.StartsWith("[") && propertyName.EndsWith("]");
138150
}
139151

140-
private static IEnumerable<string> ListReplacementTokens(string str)
152+
private static IEnumerable<(ReplacementKind, string)> ListReplacementTokens(string str)
141153
{
142154
var currentToken = new StringBuilder();
143155
var inReplacement = false;
156+
var replacementKind = ReplacementKind.None;
144157
var previousChar = '\0';
145-
var tokens = new List<string>();
146158

147159
foreach (var c in str)
148160
{
149161
if (previousChar == '$' && c == '{')
150162
{
151163
inReplacement = true;
164+
replacementKind = ReplacementKind.Raw;
165+
currentToken.Clear();
166+
}
167+
else if (previousChar == '!' && c == '{')
168+
{
169+
inReplacement = true;
170+
replacementKind = ReplacementKind.Quoted;
152171
currentToken.Clear();
153172
}
154173
else if (inReplacement && c == '}')
155174
{
156-
tokens.Add(currentToken.ToString());
175+
yield return (replacementKind, currentToken.ToString());
176+
replacementKind = ReplacementKind.None;
157177
inReplacement = false;
158178
}
159179
else if (inReplacement)
160180
currentToken.Append(c);
161181

162182
previousChar = c;
163183
}
164-
165-
return tokens;
166184
}
167185

168186
private class ReplacementKeyNotfoundException(string key) : Exception
169187
{
170188
public string Key { get; } = key;
171189
}
190+
191+
public enum ReplacementKind
192+
{
193+
None,
194+
Raw,
195+
Quoted,
196+
}
172197
}

backend/tests/Naheulbook.Tests.Functional/Functionals/Authentication.feature

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Feature: Authentication
22

33
Scenario: Can create a user with a username and a password and validate his email
44
When performing a POST to the url "/api/v2/users/" with the following json content
5-
"""
5+
"""json
66
{
77
"username": "[email protected]",
88
"password": "iHE1vAqAKZtoPdWDXW9lgOkI+SWtGV/UB59fPU6Occ602wQs1xsOywVDPLy5z6DS"
@@ -12,7 +12,7 @@ Feature: Authentication
1212
And a mail validation mail has been sent to "[email protected]"
1313

1414
When performing a POST to the url "/api/v2/users/[email protected]/validate" with the following json content
15-
"""
15+
"""json
1616
{
1717
"activationCode": "${ActivationCode}"
1818
}
@@ -23,11 +23,10 @@ Feature: Authentication
2323
Given a user identified by a password
2424

2525
When performing a POST to the url "/api/v2/users/${Username}/jwt" with the following json content
26-
"""
26+
"""json
2727
{
2828
"password": "${Password}"
2929
}
3030
"""
3131
Then the response status code is 200
32-
And the response content contains a valid JWT
33-
32+
And the response content contains a valid JWT

backend/tests/Naheulbook.Tests.Functional/Functionals/Calendar.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ Feature: Calendar
66
When performing a GET to the url "/api/v2/calendar/"
77
Then the response status code is 200
88
And the response should contains the following json
9-
"""
9+
"""json
1010
[
1111
{
12-
"id": ${Calendar.Id},
12+
"id": "!{Calendar.Id}",
1313
"name":"${Calendar.Name}",
14-
"startDay": ${Calendar.StartDay},
15-
"endDay": ${Calendar.EndDay},
14+
"startDay": "!{Calendar.StartDay}",
15+
"endDay": "!{Calendar.EndDay}",
1616
"note": "${Calendar.Note}"
1717
}
1818
]
19-
"""
19+
"""

0 commit comments

Comments
 (0)