diff --git a/pyproject.toml b/pyproject.toml index 2745151..b4db6eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ readme = "docs/index.md" authors = [ {name = "Ivan Ogasawara", email = "ivan.ogasawara@gmail.com"} ] -license = "Apache Software License 2.0" +license = "Apache-2.0" requires-python = ">=3.10,<4" dependencies = [ "pyyaml >=4", diff --git a/src/arx/parser.py b/src/arx/parser.py index 1060322..46bbfbf 100644 --- a/src/arx/parser.py +++ b/src/arx/parser.py @@ -682,7 +682,20 @@ def _default_value_for_type(self, data_type: astx.DataType) -> astx.Expr: return astx.LiteralString("") if isinstance(data_type, astx.NoneType): return astx.LiteralNone() - return astx.LiteralInt32(0) + if isinstance(data_type, astx.DateTime): + return astx.LiteralDateTime("1970-01-01T00:00:00") + if isinstance(data_type, astx.Timestamp): + return astx.LiteralTimestamp("1970-01-01T00:00:00") + if isinstance(data_type, astx.Date): + return astx.LiteralDate("1970-01-01") + if isinstance(data_type, astx.Time): + return astx.LiteralTime("00:00:00") + + raise ParserException( + f"Parser: No default value defined for type " + f"'{type(data_type).__name__}'. " + f"An explicit initializer is required." + ) def parse_type(self) -> astx.DataType: """ diff --git a/tests/test_parser_branches.py b/tests/test_parser_branches.py index 46a9ceb..e621a1d 100644 --- a/tests/test_parser_branches.py +++ b/tests/test_parser_branches.py @@ -205,10 +205,21 @@ def test_parse_type_list_and_default_values() -> None: astx.LiteralNone, ) assert isinstance( - parser._default_value_for_type(astx.DateTime()), - astx.LiteralInt32, + parser._default_value_for_type(astx.DateTime()), astx.LiteralDateTime + ) + assert isinstance( + parser._default_value_for_type(astx.Timestamp()), astx.LiteralTimestamp + ) + assert isinstance( + parser._default_value_for_type(astx.Date()), astx.LiteralDate + ) + assert isinstance( + parser._default_value_for_type(astx.Time()), astx.LiteralTime ) + with pytest.raises(ParserException): + parser._default_value_for_type(astx.ListType([astx.Int32()])) + def test_parse_unary_and_prototype_error_paths() -> None: """