Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #207 #252

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ClassMapperFieldElement extends MapperFieldElement {
_keyFor(field?.getter) ??
parent.caseStyle.transform(name);
if (key != name) {
return ", key: '$key'";
return ", key: r'$key'";
} else {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RecordMapperFieldElement extends MapperFieldElement {
String key = param.key ?? parent.caseStyle?.transform(param.name) ?? name;

if (key != name) {
return ", key: '$key'";
return ", key: r'$key'";
} else {
return '';
}
Expand Down
39 changes: 39 additions & 0 deletions packages/dart_mappable_builder/test/simple_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,44 @@ void main() {
},
);
});

// Test case for https://github.com/schultek/dart_mappable/issues/207
test('raw string as key for field', () async {
await testMappable(
{
'model': '''
import 'package:dart_mappable/dart_mappable.dart';

part 'model.mapper.dart';

@MappableRecord()
typedef FullName = (@MappableField(key: r'\$firstName') String, String);


@MappableClass()
class Rawkeymodel with RawkeymodelMappable {
final String a;
final FullName? b;

Rawkeymodel({
@MappableField(key: r'\$key') required this.a,
this.b,
});
}
''',
},
expect: {
"Rawkeymodel(a: 'hello', b: ('Max', 'Mustermann')).toMap()": equals({
r'$key': 'hello',
'b': {r'$firstName': 'Max', r'$2': 'Mustermann'}
}),
"RawkeymodelMapper.fromMap({r'\$key': 'hi', 'b': ('Max', 'Mustermann')}).toMap()":
equals({
r'$key': 'hi',
'b': {r'$firstName': 'Max', r'$2': 'Mustermann'}
}),
},
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class TempAssetWriter implements RecordingAssetWriter {

TempAssetWriter() {
var id = Random().nextInt(1e6.round());
dir = Directory.fromUri(
Uri.parse(path.join(Directory.systemTemp.path, 'mappable_$id')));
dir.createSync();
dir = Directory.systemTemp.createTempSync('mappable_$id');
}

Future<dynamic> run(String code) async {
Expand Down
Loading