From 99fb44a5b371ddad55dbe6d3cc8c254f80523cc7 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: 2025年9月10日 17:51:53 +0200 Subject: [PATCH] Fix some typos in type formats comparison Change-Id: Ie23e1d3b12e2dd11e308e706ca68f93a98908c7f Signed-off-by: Artem Goncharov --- codegenerator/common/rust.py | 30 +++++++++++------------ codegenerator/tests/unit/test_rust_sdk.py | 28 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/codegenerator/common/rust.py b/codegenerator/common/rust.py index 299fe72..e200bed 100644 --- a/codegenerator/common/rust.py +++ b/codegenerator/common/rust.py @@ -100,26 +100,26 @@ class Integer(BasePrimitiveType): elif self.minimum == -32768 and self.maximum == 32767: return "i8" - if self.format in ["int32", "i32"]: - return "i32" - elif self.format == ["int16", "i16"]: - return "i16" - elif self.format == ["int8", "i8"]: - return "i8" - elif self.format == ["uint32", "u32"]: - return "u32" - elif self.format == ["uint16", "u16"]: - return "u16" - elif self.format == ["uint8", "u8"]: - return "u8" - elif self.format == ["int64", "i64"]: + if self.format in ["int64", "i64"]: return "i64" - elif self.format == ["uint64", "u64"]: + elif self.format in ["int32", "i32"]: + return "i32" + elif self.format in ["int16", "i16"]: + return "i16" + elif self.format in ["int8", "i8"]: + return "i8" + elif self.format in ["uint64", "u64"]: return "u64" + elif self.format in ["uint32", "u32"]: + return "u32" + elif self.format in ["uint16", "u16"]: + return "u16" + elif self.format in ["uint8", "u8"]: + return "u8" return "i32" def get_sample(self): - return f"7 as {self.type_hint}" if self.type_hint != "i32" else "123" + return f"7_{self.type_hint}" if self.type_hint != "i32" else "123" class Null(BasePrimitiveType): diff --git a/codegenerator/tests/unit/test_rust_sdk.py b/codegenerator/tests/unit/test_rust_sdk.py index 39e2e86..1817d25 100644 --- a/codegenerator/tests/unit/test_rust_sdk.py +++ b/codegenerator/tests/unit/test_rust_sdk.py @@ -224,3 +224,31 @@ pub struct Request<'a> { type_model = parser.parse_schema(schema, []) rust_type = rust_sdk.TypeManager().convert_model(type_model) self.assertEqual("u8", rust_type.type_hint) + + def test_type_i64(self): + schema = {"type": "integer", "format": "int64"} + parser = model.JsonSchemaParser() + type_model = parser.parse_schema(schema, []) + rust_type = rust_sdk.TypeManager().convert_model(type_model) + self.assertEqual("i64", rust_type.type_hint) + + def test_type_i32(self): + schema = {"type": "integer", "format": "int32"} + parser = model.JsonSchemaParser() + type_model = parser.parse_schema(schema, []) + rust_type = rust_sdk.TypeManager().convert_model(type_model) + self.assertEqual("i32", rust_type.type_hint) + + def test_type_i16(self): + schema = {"type": "integer", "format": "int16"} + parser = model.JsonSchemaParser() + type_model = parser.parse_schema(schema, []) + rust_type = rust_sdk.TypeManager().convert_model(type_model) + self.assertEqual("i16", rust_type.type_hint) + + def test_type_i8(self): + schema = {"type": "integer", "format": "i8"} + parser = model.JsonSchemaParser() + type_model = parser.parse_schema(schema, []) + rust_type = rust_sdk.TypeManager().convert_model(type_model) + self.assertEqual("i8", rust_type.type_hint)

AltStyle によって変換されたページ (->オリジナル) /