-
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e62864
commit 45c9fe6
Showing
5 changed files
with
221 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
..._language_server__tests__action__generate_dynamic_decoder_for_variant_with_no_fields.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
source: compiler-core/src/language_server/tests/action.rs | ||
expression: "\npub type Wibble {\n Wibble\n}\n" | ||
--- | ||
----- BEFORE ACTION | ||
|
||
pub type Wibble { | ||
↑ | ||
Wibble | ||
} | ||
|
||
|
||
----- AFTER ACTION | ||
import gleam/dynamic/decode | ||
|
||
pub type Wibble { | ||
Wibble | ||
} | ||
|
||
fn wibble_decoder() -> decode.Decoder(Wibble) { | ||
use variant <- decode.then(decode.string) | ||
case variant { | ||
"wibble" -> decode.success(Wibble) | ||
_ -> decode.failure(todo as "Zero value for Wibble", "Wibble") | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...guage_server__tests__action__generate_dynamic_decoder_for_variants_with_mixed_fields.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
source: compiler-core/src/language_server/tests/action.rs | ||
expression: "\npub type Wibble {\n Wibble\n Wobble(field: String, field2: Int)\n}\n" | ||
--- | ||
----- BEFORE ACTION | ||
|
||
pub type Wibble { | ||
↑ | ||
Wibble | ||
Wobble(field: String, field2: Int) | ||
} | ||
|
||
|
||
----- AFTER ACTION | ||
import gleam/dynamic/decode | ||
|
||
pub type Wibble { | ||
Wibble | ||
Wobble(field: String, field2: Int) | ||
} | ||
|
||
fn wibble_decoder() -> decode.Decoder(Wibble) { | ||
use variant <- decode.field("type", decode.string) | ||
case variant { | ||
"wibble" -> decode.success(Wibble) | ||
"wobble" -> { | ||
use field <- decode.field("field", decode.string) | ||
use field2 <- decode.field("field2", decode.int) | ||
decode.success(Wobble(field:, field2:)) | ||
} | ||
_ -> decode.failure(todo as "Zero value for Wibble", "Wibble") | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...language_server__tests__action__generate_dynamic_decoder_for_variants_with_no_fields.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: compiler-core/src/language_server/tests/action.rs | ||
expression: "\npub type Wibble {\n Wibble\n Wobble\n Woo\n}\n" | ||
--- | ||
----- BEFORE ACTION | ||
|
||
pub type Wibble { | ||
↑ | ||
Wibble | ||
Wobble | ||
Woo | ||
} | ||
|
||
|
||
----- AFTER ACTION | ||
import gleam/dynamic/decode | ||
|
||
pub type Wibble { | ||
Wibble | ||
Wobble | ||
Woo | ||
} | ||
|
||
fn wibble_decoder() -> decode.Decoder(Wibble) { | ||
use variant <- decode.then(decode.string) | ||
case variant { | ||
"wibble" -> decode.success(Wibble) | ||
"wobble" -> decode.success(Wobble) | ||
"woo" -> decode.success(Woo) | ||
_ -> decode.failure(todo as "Zero value for Wibble", "Wibble") | ||
} | ||
} |