Skip to content

Commit

Permalink
Test case
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Feb 18, 2025
1 parent f648df0 commit 1168e1a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
15 changes: 15 additions & 0 deletions compiler-core/src/language_server/tests/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4427,6 +4427,21 @@ pub type Wibble {
);
}

#[test]
fn generate_dynamic_decoder_for_multi_variant_type_multi_word_name() {
assert_code_action!(
GENERATE_DYNAMIC_DECODER,
"
pub type Wibble {
OneTwo(wibble: Int, next: Wibble)
ThreeFour(wobble: Float, text: String, values: List(Bool))
FiveSixSeven(one_two: Int)
}
",
find_position_of("type").to_selection()
);
}

#[test]
fn no_code_action_to_generate_dynamic_decoder_for_type_without_labels() {
assert_no_code_actions!(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
source: compiler-core/src/language_server/tests/action.rs
assertion_line: 4432
expression: "\npub type Wibble {\n OneTwo(wibble: Int, next: Wibble)\n ThreeFour(wobble: Float, text: String, values: List(Bool))\n FiveSixSeven(one_two: Int)\n}\n"
snapshot_kind: text
---
----- BEFORE ACTION

pub type Wibble {
OneTwo(wibble: Int, next: Wibble)
ThreeFour(wobble: Float, text: String, values: List(Bool))
FiveSixSeven(one_two: Int)
}


----- AFTER ACTION
import gleam/dynamic/decode

pub type Wibble {
OneTwo(wibble: Int, next: Wibble)
ThreeFour(wobble: Float, text: String, values: List(Bool))
FiveSixSeven(one_two: Int)
}

fn wibble_decoder() -> decode.Decoder(Wibble) {
use variant <- decode.field("type", decode.string)
case variant {
"one_two" -> {
use wibble <- decode.field("wibble", decode.int)
use next <- decode.field("next", wibble_decoder())
decode.success(OneTwo(wibble:, next:))
}
"three_four" -> {
use wobble <- decode.field("wobble", decode.float)
use text <- decode.field("text", decode.string)
use values <- decode.field("values", decode.list(decode.bool))
decode.success(ThreeFour(wobble:, text:, values:))
}
"five_six_seven" -> {
use one_two <- decode.field("one_two", decode.int)
decode.success(FiveSixSeven(one_two:))
}
_ -> decode.failure(todo as "Zero value for Wibble", "Wibble")
}
}

0 comments on commit 1168e1a

Please sign in to comment.