Skip to content

Commit

Permalink
Minor updates to enum tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulf committed Aug 7, 2023
1 parent 24476ae commit 3bf21a1
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 79 deletions.
57 changes: 30 additions & 27 deletions test/enum/rust.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
/// test/rust.rs
use tsync::tsync;

/// Internally tagged enums have a key-value pair
/// that discrimate which variant it belongs to
#[derive(Serialize, Deserialize)]
#[serde(tag = "typetypetype")]
#[serde(renameAll = "kebab-case")]
#[serde(tag = "last_precedent")]
#[serde(tag = "type")]
#[tsync]
enum Message {
/// Per Enum case Docs One
UnitCaseLeft,
/// Per Enum case Docs Two
RequestLongTake {
id: String,
method: String,
params: i32,
},
Response(Response),
enum InternalTopping {
/// Tasty!
/// Not vegetarian
Pepperoni,
/// For cheese lovers
ExtraCheese { kind: String },
/// Custom toppings
/// May expire soon
Custom(CustomTopping),
}

/// The default enum conversion uses external tagging
/// Externally tagged enums ascribe the value to a key
/// that is the same as the variant name
#[tsync]
enum ExternalMessage {
/// Per Enum case Docs One
UnitCaseLeft,
/// Per Enum case Docs Two
RequestLongTake {
id: String,
method: String,
params: i32,
},
/// Newtype variant with exactly one variable
Response(Response),
enum ExternalTopping {
/// Tasty!
/// Not vegetarian
Pepperoni,
/// For cheese lovers
ExtraCheese { kind: String },
/// Custom toppings
/// May expire soon
/// Note: this test case is specifically for specifying a single type in the tuple
Custom(CustomTopping),
}

#[tsync]
struct Response {
id: String,
result: NaiveDateTime,
struct CustomTopping {
name: String,
expires_in: NaiveDateTime,
}

/// All Unit Enums go to union of constant strings
Expand All @@ -46,6 +48,7 @@ enum Animal {
Dog,
Cat,
}

#[tsync]
#[serde(rename_all = "snake_case")]
enum AnimalTwo {
Expand All @@ -60,4 +63,4 @@ enum Foo {
Bar, // 0
Baz = 123, // 123
Quux, // 124
}
}
65 changes: 39 additions & 26 deletions test/enum/typescript.d.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
/* This file is generated and managed by tsync */

type Message =
| Message__UnitCaseLeft
| Message__RequestLongTake;
/**
* Internally tagged enums have a key-value pair
* that discrimate which variant it belongs to
*/
type InternalTopping =
| InternalTopping__Pepperoni
| InternalTopping__ExtraCheese;

/** Per Enum case Docs One */
type Message__UnitCaseLeft = {
last_precedent: "UnitCaseLeft";
/**
* Tasty!
* Not vegetarian
*/
type InternalTopping__Pepperoni = {
type: "Pepperoni";
};
/** Per Enum case Docs Two */
type Message__RequestLongTake = {
last_precedent: "RequestLongTake";
id: string;
method: string;
params: number;
/** For cheese lovers */
type InternalTopping__ExtraCheese = {
type: "ExtraCheese";
kind: string;
};

/** The default enum conversion uses external tagging */
type ExternalMessage =
/** Per Enum case Docs One */
/**
* Externally tagged enums ascribe the value to a key
* that is the same as the variant name
*/
type ExternalTopping =
/**
* Tasty!
* Not vegetarian
*/
| {
"UnitCaseLeft": {}
"Pepperoni": {}
}
/** Per Enum case Docs Two */
/** For cheese lovers */
| {
"RequestLongTake": {
id: string;
method: string;
params: number;
"ExtraCheese": {
kind: string;
}
}
/** Newtype variant with exactly one variable */
| { "Response": Response };
/**
* Custom toppings
* May expire soon
* Note: this test case is specifically for specifying a single type in the tuple
*/
| { "Custom": CustomTopping };

interface Response {
id: string;
result: Date;
interface CustomTopping {
name: string;
expires_in: Date;
}

/**
Expand Down
65 changes: 39 additions & 26 deletions test/enum/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
/* This file is generated and managed by tsync */

export type Message =
| Message__UnitCaseLeft
| Message__RequestLongTake;
/**
* Internally tagged enums have a key-value pair
* that discrimate which variant it belongs to
*/
export type InternalTopping =
| InternalTopping__Pepperoni
| InternalTopping__ExtraCheese;

/** Per Enum case Docs One */
type Message__UnitCaseLeft = {
last_precedent: "UnitCaseLeft";
/**
* Tasty!
* Not vegetarian
*/
type InternalTopping__Pepperoni = {
type: "Pepperoni";
};
/** Per Enum case Docs Two */
type Message__RequestLongTake = {
last_precedent: "RequestLongTake";
id: string;
method: string;
params: number;
/** For cheese lovers */
type InternalTopping__ExtraCheese = {
type: "ExtraCheese";
kind: string;
};

/** The default enum conversion uses external tagging */
export type ExternalMessage =
/** Per Enum case Docs One */
/**
* Externally tagged enums ascribe the value to a key
* that is the same as the variant name
*/
export type ExternalTopping =
/**
* Tasty!
* Not vegetarian
*/
| {
"UnitCaseLeft": {}
"Pepperoni": {}
}
/** Per Enum case Docs Two */
/** For cheese lovers */
| {
"RequestLongTake": {
id: string;
method: string;
params: number;
"ExtraCheese": {
kind: string;
}
}
/** Newtype variant with exactly one variable */
| { "Response": Response };
/**
* Custom toppings
* May expire soon
* Note: this test case is specifically for specifying a single type in the tuple
*/
| { "Custom": CustomTopping };

export interface Response {
id: string;
result: Date;
export interface CustomTopping {
name: string;
expires_in: Date;
}

/**
Expand Down

0 comments on commit 3bf21a1

Please sign in to comment.