Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T05:42:18.307Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

search.rs

181 lines · 4.8 KB · rust
1use language::Buffer;
2use project::search::SearchQuery;
3use text::Rope;
4use util::{
5    paths::{PathMatcher, PathStyle},
6    rel_path::RelPath,
7};
8
9#[test]
10fn path_matcher_creation_for_valid_paths() {
11    for valid_path in [
12        "file",
13        "Cargo.toml",
14        ".DS_Store",
15        "~/dir/another_dir/",
16        "./dir/file",
17        "dir/[a-z].txt",
18    ] {
19        let path_matcher = PathMatcher::new(&[valid_path.to_owned()], PathStyle::local())
20            .unwrap_or_else(|e| panic!("Valid path {valid_path} should be accepted, but got: {e}"));
21        assert!(
22            path_matcher.is_match(&RelPath::new(valid_path.as_ref(), PathStyle::local()).unwrap()),
23            "Path matcher for valid path {valid_path} should match itself"
24        )
25    }
26}
27
28#[test]
29fn path_matcher_creation_for_globs() {
30    for invalid_glob in ["dir/[].txt", "dir/[a-z.txt", "dir/{file"] {
31        match PathMatcher::new(&[invalid_glob.to_owned()], PathStyle::local()) {
32            Ok(_) => panic!("Invalid glob {invalid_glob} should not be accepted"),
33            Err(_expected) => {}
34        }
35    }
36
37    for valid_glob in [
38        "dir/?ile",
39        "dir/*.txt",
40        "dir/**/file",
41        "dir/[a-z].txt",
42        "{dir,file}",
43    ] {
44        match PathMatcher::new(&[valid_glob.to_owned()], PathStyle::local()) {
45            Ok(_expected) => {}
46            Err(e) => panic!("Valid glob should be accepted, but got: {e}"),
47        }
48    }
49}
50
51#[test]
52fn test_case_sensitive_pattern_items() {
53    let case_sensitive = false;
54    let search_query = SearchQuery::regex(
55        "test\\C",
56        false,
57        case_sensitive,
58        false,
59        false,
60        Default::default(),
61        Default::default(),
62        false,
63        None,
64    )
65    .expect("Should be able to create a regex SearchQuery");
66
67    assert_eq!(
68        search_query.case_sensitive(),
69        true,
70        "Case sensitivity should be enabled when \\C pattern item is present in the query."
71    );
72
73    let case_sensitive = true;
74    let search_query = SearchQuery::regex(
75        "test\\c",
76        true,
77        case_sensitive,
78        false,
79        false,
80        Default::default(),
81        Default::default(),
82        false,
83        None,
84    )
85    .expect("Should be able to create a regex SearchQuery");
86
87    assert_eq!(
88        search_query.case_sensitive(),
89        false,
90        "Case sensitivity should be disabled when \\c pattern item is present, even if initially set to true."
91    );
92
93    let case_sensitive = false;
94    let search_query = SearchQuery::regex(
95        "test\\c\\C",
96        false,
97        case_sensitive,
98        false,
99        false,
100        Default::default(),
101        Default::default(),
102        false,
103        None,
104    )
105    .expect("Should be able to create a regex SearchQuery");
106
107    assert_eq!(
108        search_query.case_sensitive(),
109        true,
110        "Case sensitivity should be enabled when \\C is the last pattern item, even after a \\c."
111    );
112
113    let case_sensitive = false;
114    let search_query = SearchQuery::regex(
115        "tests\\\\C",
116        false,
117        case_sensitive,
118        false,
119        false,
120        Default::default(),
121        Default::default(),
122        false,
123        None,
124    )
125    .expect("Should be able to create a regex SearchQuery");
126
127    assert_eq!(
128        search_query.case_sensitive(),
129        false,
130        "Case sensitivity should not be enabled when \\C pattern item is preceded by a backslash."
131    );
132}
133
134#[gpui::test]
135async fn test_multiline_regex_crlf(cx: &mut gpui::TestAppContext) {
136    let search_query = SearchQuery::regex(
137        "^hello$\r?\n",
138        false,
139        false,
140        false,
141        false,
142        Default::default(),
143        Default::default(),
144        false,
145        None,
146    )
147    .expect("Should be able to create a regex SearchQuery");
148
149    let text = Rope::from("hello\r\nworld\r\nhello\r\nworld");
150    let snapshot = cx
151        .update(|app| Buffer::build_snapshot(text, None, None, None, app))
152        .await;
153
154    let results = search_query.search(&snapshot, None).await;
155    assert_eq!(results, vec![0..7, 14..21]);
156}
157
158#[gpui::test]
159async fn test_multiline_regex(cx: &mut gpui::TestAppContext) {
160    let search_query = SearchQuery::regex(
161        "^hello$\n",
162        false,
163        false,
164        false,
165        false,
166        Default::default(),
167        Default::default(),
168        false,
169        None,
170    )
171    .expect("Should be able to create a regex SearchQuery");
172
173    let text = Rope::from("hello\nworld\nhello\nworld");
174    let snapshot = cx
175        .update(|app| Buffer::build_snapshot(text, None, None, None, app))
176        .await;
177
178    let results = search_query.search(&snapshot, None).await;
179    assert_eq!(results, vec![0..6, 12..18]);
180}
181
Served at tenant.openagents/omega Member data and write actions are omitted.