microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
source/language_service/src/completion/tests/openqasm.rs
106lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use crate::{completion::tests::check, test_utils::openqasm::compile_with_markers}; |
| 5 | use expect_test::{Expect, expect}; |
| 6 | use indoc::indoc; |
| 7 | |
| 8 | fn check_single_file(source_with_cursor: &str, completions_to_check: &[&str], expect: &Expect) { |
| 9 | let (compilation, cursor_position, _) = compile_with_markers(source_with_cursor); |
| 10 | |
| 11 | check( |
| 12 | &compilation, |
| 13 | "<source>", |
| 14 | cursor_position, |
| 15 | completions_to_check, |
| 16 | expect, |
| 17 | ); |
| 18 | } |
| 19 | |
| 20 | #[test] |
| 21 | fn in_empty_file_contains_openqasm() { |
| 22 | check_single_file( |
| 23 | indoc! {r#" |
| 24 | ↘ |
| 25 | }"#}, |
| 26 | &["OPENQASM"], |
| 27 | &expect![[r#" |
| 28 | found, sorted: |
| 29 | "OPENQASM" (Keyword) |
| 30 | "#]], |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | #[test] |
| 35 | fn in_file_after_openqasm_contains_keywords_containing_i() { |
| 36 | check_single_file( |
| 37 | indoc! {r#" |
| 38 | OPENQASM 3.0; |
| 39 | i↘ |
| 40 | }"#}, |
| 41 | &["if", "include", "input", "inv"], |
| 42 | &expect![[r#" |
| 43 | found, sorted: |
| 44 | "if" (Keyword) |
| 45 | "include" (Keyword) |
| 46 | "input" (Keyword) |
| 47 | "inv" (Keyword) |
| 48 | "#]], |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | #[test] |
| 53 | fn in_file_after_openqasm_contains_annotations_containing_i() { |
| 54 | check_single_file( |
| 55 | indoc! {r#" |
| 56 | OPENQASM 3.0; |
| 57 | i↘ |
| 58 | }"#}, |
| 59 | &["SimulatableIntrinsic"], |
| 60 | &expect![[r#" |
| 61 | found, sorted: |
| 62 | "SimulatableIntrinsic" (Interface) |
| 63 | "#]], |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | #[test] |
| 68 | fn local_vars() { |
| 69 | check_single_file( |
| 70 | indoc! {r#" |
| 71 | OPENQASM 3.0; |
| 72 | input int num_samples; |
| 73 | output float angle_value; |
| 74 | ↘ |
| 75 | }"#}, |
| 76 | &["num_samples", "angle_value"], |
| 77 | &expect![[r#" |
| 78 | found, sorted: |
| 79 | "angle_value" (Variable) |
| 80 | detail: "angle_value : Double" |
| 81 | "num_samples" (Variable) |
| 82 | detail: "num_samples : Int" |
| 83 | "#]], |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | #[test] |
| 88 | fn local_vars_doesnt_pick_up_variables_declared_after_cursor() { |
| 89 | check_single_file( |
| 90 | indoc! {r#" |
| 91 | OPENQASM 3.0; |
| 92 | input int num_samples; |
| 93 | ↘ |
| 94 | output float angle_value; |
| 95 | }"#}, |
| 96 | &["num_samples", "angle_value"], |
| 97 | &expect![[r#" |
| 98 | found, sorted: |
| 99 | "num_samples" (Variable) |
| 100 | detail: "num_samples : Int" |
| 101 | |
| 102 | not found: |
| 103 | "angle_value" |
| 104 | "#]], |
| 105 | ); |
| 106 | } |