Debian Codegraph @

src/text.rs

raw symbols SCIP
1 //! Text-based utilities for navigating Makefile source text.
2 //!
3 //! These functions work on raw source text (not the syntax tree) and are useful
4 //! for editor integrations that need to understand what is at a given cursor position.
5
6 /// Extract a variable name from `$(VAR)` or `${VAR}` surrounding the given byte offset.
7 ///
8 /// Returns `None` if the offset is not inside a variable reference.
9 ///
10 /// # Example
11 /// ```
12 /// use makefile_lossless::variable_at_offset;
13 /// assert_eq!(variable_at_offset("$(FOO)", 2), Some("FOO"));
14 /// assert_eq!(variable_at_offset("${BAR}", 3), Some("BAR"));
15 /// assert_eq!(variable_at_offset("plain text", 3), None);
16 /// ```
17 pub fn variable_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/variable_at_offset().(text: &str, offset: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> {
18 let bytes = text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().();
19 let mut start = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
20 let mut i = offset;
21 while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().2 {
22 i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
23 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && (bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'(' || bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'{') && bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'$' {
24 start = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1);
25 break;
26 }
27 if bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b')' || bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'}' || bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'\n' {
28 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
29 }
30 }
31 let start = start?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
32 let rest = &text[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
33 let end = rest.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().([')', '}'])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
34 let var_name = &rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
35 if offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().start && offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().end {
36 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(var_name)
37 } else {
38 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
39 }
40 }
41
42 /// Extract the word (identifier) at the given byte offset.
43 ///
44 /// A word consists of ASCII alphanumeric characters, underscores, dots, and hyphens.
45 /// Returns `None` if the offset is not on a word character.
46 ///
47 /// # Example
48 /// ```
49 /// use makefile_lossless::word_at_offset;
50 /// assert_eq!(word_at_offset("hello world", 0), Some("hello"));
51 /// assert_eq!(word_at_offset("hello world", 5), None); // space
52 /// assert_eq!(word_at_offset("hello world", 6), Some("world"));
53 /// ```
54 pub fn word_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/word_at_offset().(text: &str, offset: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> {
55 if offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().text.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() {
56 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
57 }
58 let bytes = text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().();
59 let is_ident = |b: u8| b.is_ascii_alphanumericrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_alphanumeric().() || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'_' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'.' || b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'-';
60 if offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().text.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_ident(bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().offset]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) {
61 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
62 }
63 let start = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#offset)
64 .revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().()
65 .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|&i| is_ident(bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().))
66 .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().()
67 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(offset);
68 let end = (offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#text.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().())
69 .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|&i| is_ident(bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().))
70 .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().()
71 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|i| i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1)
72 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(offset);
73 if start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().end {
74 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
75 }
76 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&text[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)
77 }
78
79 /// Determine if the given byte offset is in the prerequisites area of a rule line
80 /// (i.e. after the first `:` on a non-recipe line).
81 ///
82 /// # Example
83 /// ```
84 /// use makefile_lossless::is_in_prerequisites;
85 /// let text = "all: build test\n\techo ok\n";
86 /// assert!(!is_in_prerequisites(text, 0)); // 'a' in target
87 /// assert!(is_in_prerequisites(text, 5)); // 'b' in prerequisites
88 /// assert!(!is_in_prerequisites(text, 17)); // 'e' in recipe
89 /// ```
90 pub fn is_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 text/is_in_prerequisites().(text: &str, offset: usize) -> bool {
91 let line_start = text[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#offset]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..rfindrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rfind().('\n').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|i| i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0);
92 let line = &text[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().line_start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
93 // Recipe lines start with a tab
94 if line.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('\t') {
95 return false;
96 }
97 let col = offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().line_start;
98 // Check if there's a `:` before our position on this line
99 line[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#col]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(':')
100 }
101
102 #[cfg(test)]
103 mod testsrust-analyzer cargo makefile-lossless 0.3.40 text/tests/ {
104 use superrust-analyzer cargo makefile-lossless 0.3.40 text/::*;
105
106 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
107 fn test_variable_at_offset_parensrust-analyzer cargo makefile-lossless 0.3.40 text/tests/test_variable_at_offset_parens().() {
108 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/variable_at_offset().("$(FOO)", 2), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("FOO"));
109 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/variable_at_offset().("$(FOO)", 4), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("FOO"));
110 }
111
112 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
113 fn test_variable_at_offset_bracesrust-analyzer cargo makefile-lossless 0.3.40 text/tests/test_variable_at_offset_braces().() {
114 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/variable_at_offset().("${BAR}", 2), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("BAR"));
115 }
116
117 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
118 fn test_variable_at_offset_nonerust-analyzer cargo makefile-lossless 0.3.40 text/tests/test_variable_at_offset_none().() {
119 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/variable_at_offset().("plain text", 3), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
120 }
121
122 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
123 fn test_variable_at_offset_nested_contextrust-analyzer cargo makefile-lossless 0.3.40 text/tests/test_variable_at_offset_nested_context().() {
124 let text = "\t$(CC) main.c";
125 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/variable_at_offset().(text, 3), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("CC"));
126 }
127
128 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
129 fn test_word_at_offset_basicrust-analyzer cargo makefile-lossless 0.3.40 text/tests/test_word_at_offset_basic().() {
130 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(word_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/word_at_offset().("hello world", 0), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("hello"));
131 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(word_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/word_at_offset().("hello world", 3), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("hello"));
132 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(word_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/word_at_offset().("hello world", 5), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
133 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(word_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/word_at_offset().("hello world", 6), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("world"));
134 }
135
136 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
137 fn test_word_at_offset_special_charsrust-analyzer cargo makefile-lossless 0.3.40 text/tests/test_word_at_offset_special_chars().() {
138 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(word_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/word_at_offset().("foo-bar.o", 0), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("foo-bar.o"));
139 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(word_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/word_at_offset().("FOO_BAR", 3), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("FOO_BAR"));
140 }
141
142 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
143 fn test_is_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 text/tests/test_is_in_prerequisites().() {
144 let text = "all: build test\n\techo ok\n";
145 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 text/is_in_prerequisites().(text, 0)); // 'a' in target
146 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 text/is_in_prerequisites().(text, 5)); // 'b' in prerequisites
147 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 text/is_in_prerequisites().(text, 17)); // 'e' in recipe
148 }
149
150 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
151 fn test_is_in_prerequisites_no_colonrust-analyzer cargo makefile-lossless 0.3.40 text/tests/test_is_in_prerequisites_no_colon().() {
152 let text = "VAR = value\n";
153 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 text/is_in_prerequisites().(text, 6));
154 }
155 }