Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion lib/factory/token_set_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ String generateTokenSetEnum(
// Tuple: (prefix, initial match)
final prefixes = [
...matches.map((match) => Tuple2(match.group(1), match.group(0))),
...nonMatchedSets.map((noMatch) => Tuple2(noMatch, noMatch))
...nonMatchedSets.map((noMatch) => Tuple2(noMatch, noMatch)),
];

// A list of all unique prefixes.
Expand Down
19 changes: 13 additions & 6 deletions lib/parsers/dimension_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:design_tokens_builder/parsers/design_token_parser.dart';
/// E.g.
/// Figma design tokens:
/// "value": "14" or
/// "value": "14px"
/// "value": "14px" or
/// "value": 14
///
/// Flutter generated code:
/// 14.0
Expand All @@ -32,11 +33,17 @@ class DimensionParser extends DesignTokenParser {

@override
String buildValue(value) {
if (value is String) {
final pixel = double.parse(value.split('px').first);
return pixel.toString();
late final double pixel;
switch (value.runtimeType) {
case String:
pixel = double.parse(value.split('px').first);
break;
case int:
pixel = value.toDouble();
break;
default:
throw Exception('Unable to parse dimension value with data: $value');
}

throw Exception('Unable to parse dimension value with data: $value');
return pixel.toString();
}
}
2 changes: 1 addition & 1 deletion test/builder_config/builder_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main() {
'fontConfig': [
{'family': 'First Font', 'flutterName': 'FirstFont'},
{'family': 'Second Font', 'flutterName': 'SecondFont'},
]
],
});

print(BuilderConfig.fromYaml(yaml));
Expand Down
14 changes: 7 additions & 7 deletions test/factory/context_extension_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ void main() {
'color6': {'value': '#9f35a5', 'type': 'color'},
'color7': {'value': '#73c118', 'type': 'color'},
'color8': {'value': '#ed0c8d', 'type': 'color'},
'color9': {'value': '#8800ff', 'type': 'color'}
}
'color9': {'value': '#8800ff', 'type': 'color'},
},
},
'\$metadata': {
'tokenSetOrder': [
'dark',
]
}
],
},
},
config: config,
);
Expand All @@ -48,13 +48,13 @@ void main() {
'dark': {
'sys': {
'primary': {'value': '#f8e912', 'type': 'color'},
}
},
},
'\$metadata': {
'tokenSetOrder': [
'dark',
]
}
],
},
},
config: config,
);
Expand Down
2 changes: 1 addition & 1 deletion test/factory/token_set_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void main() {
'dark',
'allyLight',
'allyDark',
'custom'
'custom',
];

final result = generateTokenSetEnum(tokenSets, config: config);
Expand Down
24 changes: 12 additions & 12 deletions test/parsers/box_shadow_parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ void main() {
group('build value', () {
test('1 shadow', () {
final map = {
'x': '4',
'y': '2',
'spread': '3',
'x': 4,
'y': 2,
'spread': 3,
'color': '#FFFFFF',
'blur': '5',
'blur': 5,
'type': 'dropShadow',
};

Expand All @@ -29,19 +29,19 @@ void main() {
test('multiple shadows', () {
final map = [
{
'x': '4',
'y': '2',
'spread': '3',
'x': 4,
'y': 2,
'spread': 3,
'color': '#FFFFFF',
'blur': '5',
'blur': 5,
'type': 'dropShadow',
},
{
'x': '4',
'y': '2',
'spread': '3',
'x': 4,
'y': 2,
'spread': 3,
'color': '#FFFFFF',
'blur': '5',
'blur': 5,
'type': 'innerShadow',
},
];
Expand Down
7 changes: 6 additions & 1 deletion test/parsers/dimension_parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ void main() {
expect(result, '69.0');
});

test('should succeed when the input value is of type int', () {
final result = parser.buildValue(96);
expect(result, '96.0');
});

test('fails', () {
expect(() => parser.buildValue(1), throwsException);
expect(() => parser.buildValue(1.0), throwsException);
expect(() => parser.buildValue('some value'), throwsException);
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/utils/token_set_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ void main() {
'small': {'value': 'Some value', 'type': 'someType'},
'medium': {'value': 'Some value', 'type': 'someType 3'},
'display': {
'large': {'value': 'Some value', 'type': 'someType'}
'large': {'value': 'Some value', 'type': 'someType'},
},
},
);

expect(result, {
'small': {'value': 'Some value', 'type': 'someType'},
'display': {
'large': {'value': 'Some value', 'type': 'someType'}
'large': {'value': 'Some value', 'type': 'someType'},
},
});
expect(result['medium'], null);
Expand All @@ -119,7 +119,7 @@ void main() {
'small': {'value': 'Some new value', 'type': 'someType'},
'medium': {'value': 'Some value', 'type': 'someType 3'},
'display': {
'large': {'value': 'Some value', 'type': 'someType'}
'large': {'value': 'Some value', 'type': 'someType'},
},
},
fallbackSetData: {
Expand All @@ -132,7 +132,7 @@ void main() {
expect(result['small'], {'value': 'Some new value', 'type': 'someType'});
expect(result['large'], {'value': 'Some value', 'type': 'someType'});
expect(result['display'], {
'large': {'value': 'Some value', 'type': 'someType'}
'large': {'value': 'Some value', 'type': 'someType'},
});
expect(result['medium'], null);
});
Expand Down
6 changes: 3 additions & 3 deletions test/utils/typography_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() {
'textCase': 'none',
'textDecoration': 'none',
},
'type': 'typography'
'type': 'typography',
},
},
});
Expand All @@ -35,8 +35,8 @@ void main() {
'textCase': 'none',
'textDecoration': 'none',
},
'type': 'typography'
}
'type': 'typography',
},
});
});
}