@@ -594,7 +594,10 @@ impl ContextProvider for GoContextProvider {
),
],
cwd: package_cwd.clone(),
- tags: vec!["go-table-test-case".to_owned()],
+ tags: vec![
+ "go-table-test-case".to_owned(),
+ "go-table-test-case-without-explicit-variable".to_owned(),
+ ],
..TaskTemplate::default()
},
TaskTemplate {
@@ -1117,6 +1120,149 @@ mod tests {
// );
}
+ #[gpui::test]
+ fn test_go_table_test_slice_without_explicit_variable_detection(cx: &mut TestAppContext) {
+ let language = language("go", tree_sitter_go::LANGUAGE.into());
+
+ let table_test = r#"
+ package main
+
+ import "testing"
+
+ func TestExample(t *testing.T) {
+ for _, tc := range []struct{
+ name string
+ anotherStr string
+ }{
+ {
+ name: "test case 1",
+ anotherStr: "foo",
+ },
+ {
+ name: "test case 2",
+ anotherStr: "bar",
+ },
+ {
+ name: "test case 3",
+ anotherStr: "baz",
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ // test code here
+ })
+ }
+ }
+ "#;
+
+ let buffer =
+ cx.new(|cx| crate::Buffer::local(table_test, cx).with_language(language.clone(), cx));
+ cx.executor().run_until_parked();
+
+ let runnables: Vec<_> = buffer.update(cx, |buffer, _| {
+ let snapshot = buffer.snapshot();
+ snapshot.runnable_ranges(0..table_test.len()).collect()
+ });
+
+ let tag_strings: Vec<String> = runnables
+ .iter()
+ .flat_map(|r| &r.runnable.tags)
+ .map(|tag| tag.0.to_string())
+ .collect();
+
+ assert!(
+ tag_strings.contains(&"go-test".to_string()),
+ "Should find go-test tag, found: {:?}",
+ tag_strings
+ );
+ assert!(
+ tag_strings.contains(&"go-table-test-case-without-explicit-variable".to_string()),
+ "Should find go-table-test-case-without-explicit-variable tag, found: {:?}",
+ tag_strings
+ );
+
+ let go_test_count = tag_strings.iter().filter(|&tag| tag == "go-test").count();
+
+ assert!(
+ go_test_count == 1,
+ "Should find exactly 1 go-test, found: {}",
+ go_test_count
+ );
+ }
+
+ #[gpui::test]
+ fn test_go_table_test_map_without_explicit_variable_detection(cx: &mut TestAppContext) {
+ let language = language("go", tree_sitter_go::LANGUAGE.into());
+
+ let table_test = r#"
+ package main
+
+ import "testing"
+
+ func TestExample(t *testing.T) {
+ for name, tc := range map[string]struct {
+ someStr string
+ fail bool
+ }{
+ "test failure": {
+ someStr: "foo",
+ fail: true,
+ },
+ "test success": {
+ someStr: "bar",
+ fail: false,
+ },
+ } {
+ t.Run(name, func(t *testing.T) {
+ // test code here
+ })
+ }
+ }
+ "#;
+
+ let buffer =
+ cx.new(|cx| crate::Buffer::local(table_test, cx).with_language(language.clone(), cx));
+ cx.executor().run_until_parked();
+
+ let runnables: Vec<_> = buffer.update(cx, |buffer, _| {
+ let snapshot = buffer.snapshot();
+ snapshot.runnable_ranges(0..table_test.len()).collect()
+ });
+
+ let tag_strings: Vec<String> = runnables
+ .iter()
+ .flat_map(|r| &r.runnable.tags)
+ .map(|tag| tag.0.to_string())
+ .collect();
+
+ assert!(
+ tag_strings.contains(&"go-test".to_string()),
+ "Should find go-test tag, found: {:?}",
+ tag_strings
+ );
+ assert!(
+ tag_strings.contains(&"go-table-test-case-without-explicit-variable".to_string()),
+ "Should find go-table-test-case-without-explicit-variable tag, found: {:?}",
+ tag_strings
+ );
+
+ let go_test_count = tag_strings.iter().filter(|&tag| tag == "go-test").count();
+ let go_table_test_count = tag_strings
+ .iter()
+ .filter(|&tag| tag == "go-table-test-case-without-explicit-variable")
+ .count();
+
+ assert!(
+ go_test_count == 1,
+ "Should find exactly 1 go-test, found: {}",
+ go_test_count
+ );
+ assert!(
+ go_table_test_count == 2,
+ "Should find exactly 2 go-table-test-case-without-explicit-variable, found: {}",
+ go_table_test_count
+ );
+ }
+
#[gpui::test]
fn test_go_table_test_slice_ignored(cx: &mut TestAppContext) {
let language = language("go", tree_sitter_go::LANGUAGE.into());