Skip to content

Commit

Permalink
Add test cases to validate short and byte values
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Oct 15, 2024
1 parent 3e40148 commit a05d61b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
64 changes: 64 additions & 0 deletions ballerina/tests/primitive_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,67 @@ public isolated function testNullValuesWithNonNullData() returns error? {
byte[]|error serializedValue = avro.toAvro("string");
test:assertTrue(serializedValue is error);
}

@test:Config {
groups: ["primitive"]
}
public isolated function testUnsignedShortValue() returns error? {
string schema = string `
{
"type": "int",
"name" : "shortValue",
"namespace": "data"
}`;

int:Unsigned8 value = 255;
return verifyOperation(int:Unsigned8, value, schema);
}

@test:Config {
groups: ["primitive", "check"]
}
public isolated function testSignedShortValue() returns error? {
string schema = string `
{
"type": "int",
"name" : "shortValue",
"namespace": "data"
}`;

int:Signed32 value = 555950000;
return verifyOperation(int:Signed32, value, schema);
}

@test:Config {
groups: ["primitive", "check"]
}
public isolated function testSignedMinusShortValue() returns error? {
string schema = string `
{
"type": "double",
"name" : "shortValue",
"namespace": "data"
}`;

int:Signed32 value = -2147483;
Schema avro = check new (schema);
byte[] serializedValue = check avro.toAvro(value);
float deserializedValue = check avro.fromAvro(serializedValue);
test:assertEquals(deserializedValue, -2147483.0);
}

@test:Config {
groups: ["primitive", "check"]
}
public isolated function testByteValue() returns error? {
string schema = string `
{
"type": "bytes",
"name" : "byteValue",
"namespace": "data"
}`;
byte[] data = [];
byte value = 2;
data.push(value);
return verifyOperation(ByteArray, data, schema);
}
31 changes: 30 additions & 1 deletion ballerina/tests/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ public type Envelope2 record {
string? MessageSource;
};


public type UnionEnumRecord record {
string|Numbers? field1;
};
Expand All @@ -288,6 +287,36 @@ public type ReadOnlyRec readonly & record {
string|UnionEnumRecord? & readonly field1;
};

type Record record {
decimal? hrdCasinoGgrLt;
string? hrdAccountCreationTimestamp;
float? hrdSportsBetCountLifetime;
float? hrdSportsFreeBetAmountLifetime;
string? hriUnityId;
string? hrdLastRealMoneySportsbookBetTs;
string? hrdLoyaltyTier;
string? rowInsertTimestampEst;
float? ltvSports365Total;
string? hrdFirstDepositTimestamp;
boolean? hrdVipStatus;
string? hrdLastRealMoneyCasinoWagerTs;
float? hrdSportsCashBetAmountLifetime;
string? hrdAccountStatus;
string? hrdAccountId;
float? ltvAllVerticals365Total;
boolean? hrdOptInSms;
float? ltvCasino365Total;
string? hrdAccountSubStatus;
float? hrdCasinoTotalWagerLifetime;
float? hrdSportsGgrLt;
string? currentGeoSegment;
string? kycStatus;
string? signupGeoSegment;
float? hrdSportsBetAmountLifetime;
boolean? hrdOptInEmail;
boolean? hrdOptInPush;
};

type ReadOnlyUnionFixed UnionFixedRecord & readonly;
type ByteArray byte[];
type ReadOnlyIntArray int[] & readonly;
Expand Down

0 comments on commit a05d61b

Please sign in to comment.