Skip to content

Commit

Permalink
Add braces tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fasust committed Oct 1, 2024
1 parent b617224 commit ff80a68
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions slang/lib/src/builder/utils/string_interpolation_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ String _replaceBetween({
}
}

if (startIndex >= 2 &&
curr[startIndex - 1] == ':' &&
curr[startIndex - 2] == '@') {
// ignore because of preceding @: which indicates an escaped, linked translation
buffer.write(curr.substring(0, startIndex + 1));
if (startIndex + 1 < curr.length) {
curr = curr.substring(startIndex + startCharacterLength);
continue;
} else {
break;
}
}

if (startIndex != 0) {
// add prefix
buffer.write(curr.substring(0, startIndex));
Expand Down
34 changes: 34 additions & 0 deletions slang/test/unit/model/node_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,23 @@ void main() {
expect(node.content, r'Nice ${coolHi} ${wow} ${yes}a ${noYes}');
expect(node.params, {'coolHi', 'wow', 'yes', 'noYes'});
});

test('with links', () {
final test = r'{myArg} @:myLink';
final node = textNode(test, StringInterpolation.braces);
expect(node.content, r'${myArg} ${_root.myLink}');
expect(node.params, <String>{'myArg'});
});

test('with escaped links', () {
final test = r'{myArg} @:linkA @:{linkB}hello @:{linkC}';
final node = textNode(test, StringInterpolation.braces);
expect(
node.content,
r'${myArg} ${_root.linkA} ${_root.linkB}hello ${_root.linkC}',
);
expect(node.params, <String>{'myArg'});
});
});

group(StringInterpolation.doubleBraces, () {
Expand Down Expand Up @@ -414,6 +431,23 @@ void main() {
expect(node.content, r'Nice ${coolHi} ${wow} ${yes}a ${noYes}');
expect(node.params, {'coolHi', 'wow', 'yes', 'noYes'});
});

test('with links', () {
final test = r'{{myArg}} @:myLink';
final node = textNode(test, StringInterpolation.doubleBraces);
expect(node.content, r'${myArg} ${_root.myLink}');
expect(node.params, <String>{'myArg'});
});

test('with escaped links', () {
final test = r'{{myArg}} @:linkA @:{linkB}hello @:{linkC}';
final node = textNode(test, StringInterpolation.doubleBraces);
expect(
node.content,
r'${myArg} ${_root.linkA} ${_root.linkB}hello ${_root.linkC}',
);
expect(node.params, <String>{'myArg'});
});
});
});

Expand Down

0 comments on commit ff80a68

Please sign in to comment.