Debian Codegraph @

src/ast/variable.rs

raw symbols SCIP
1 use superrust-analyzer cargo makefile-lossless 0.3.40 ast/::makefilerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/::MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#;
2 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::{remove_with_preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 lossless/remove_with_preceding_comments()., VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#};
3 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::*;
4 use rowanrust-analyzer cargo rowan 0.16.1 crate/::astrust-analyzer cargo rowan 0.16.1 ast/::AstNoderust-analyzer cargo rowan 0.16.1 ast/AstNode#;
5 use rowanrust-analyzer cargo rowan 0.16.1 crate/::{GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#, SyntaxNoderust-analyzer cargo rowan 0.16.1 api/SyntaxNode#};
6
7 /// Recursively rebuild a syntax node into a GreenNodeBuilder.
8 fn rebuild_noderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/rebuild_node().(builder: &mut GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#, node: &craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#) {
9 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(node.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
10 for child in node.children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
11 match child {
12 rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Tokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Token#(token) => {
13 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
14 }
15 rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Noderust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Node#(child_node) => {
16 rebuild_noderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/rebuild_node().(builder, &child_node);
17 }
18 }
19 }
20 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
21 }
22
23 impl VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition# {
24 /// Get the name of the variable definition
25 pub fn namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
26 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|it| {
27 it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|it| {
28 if it.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#
29 && it.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."export"
30 && it.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."override"
31 && it.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."define"
32 {
33 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(it.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
34 } else {
35 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
36 }
37 })
38 })
39 }
40
41 /// Returns true if this assignment is a `define` ... `endef` block.
42 pub fn is_definerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_define().(&self) -> bool {
43 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|it| {
44 it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().()
45 .is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(|t| t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# && t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."define")
46 })
47 }
48
49 /// Check if this variable definition is exported
50 pub fn is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().(&self) -> bool {
51 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().()
52 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
53 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|it| it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(|token| token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."export"))
54 }
55
56 /// Check if this variable definition uses the `override` directive
57 ///
58 /// `override FOO = bar` makes the assignment take precedence over any
59 /// value passed on the make command line.
60 ///
61 /// # Example
62 /// ```
63 /// use makefile_lossless::Makefile;
64 /// let makefile: Makefile = "override CC = clang\n".parse().unwrap();
65 /// let var = makefile.variable_definitions().next().unwrap();
66 /// assert!(var.is_override());
67 /// assert_eq!(var.name(), Some("CC".to_string()));
68 /// ```
69 pub fn is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().(&self) -> bool {
70 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|it| {
71 it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().()
72 .is_some_andrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some_and().(|token| token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."override")
73 })
74 }
75
76 /// Get the assignment operator/flavor used in this variable definition
77 ///
78 /// Returns the operator as a string: "=", ":=", "::=", ":::=", "+=", "?=", or "!="
79 ///
80 /// # Example
81 /// ```
82 /// use makefile_lossless::Makefile;
83 /// let makefile: Makefile = "VAR := value\n".parse().unwrap();
84 /// let var = makefile.variable_definitions().next().unwrap();
85 /// assert_eq!(var.assignment_operator(), Some(":=".to_string()));
86 /// ```
87 pub fn assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
88 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|it| {
89 it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|token| {
90 if token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# {
91 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
92 } else {
93 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
94 }
95 })
96 })
97 }
98
99 /// Get the raw value of the variable definition
100 pub fn raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
101 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().()
102 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
103 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|it| it.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#)
104 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|it| it.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
105 }
106
107 /// Get the parent item of this variable definition, if any
108 ///
109 /// Returns `Some(MakefileItem)` if this variable has a parent that is a MakefileItem
110 /// (e.g., a Conditional), or `None` if the parent is the root Makefile node.
111 ///
112 /// # Example
113 /// ```
114 /// use makefile_lossless::Makefile;
115 ///
116 /// let makefile: Makefile = r#"ifdef DEBUG
117 /// VAR = value
118 /// endif
119 /// "#.parse().unwrap();
120 /// let cond = makefile.conditionals().next().unwrap();
121 /// let var = cond.if_items().next().unwrap();
122 /// // Variable's parent is the conditional
123 /// assert!(matches!(var, makefile_lossless::MakefileItem::Variable(_)));
124 /// ```
125 pub fn parentrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]parent().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#> {
126 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::castrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]cast().)
127 }
128
129 /// Remove this variable definition from its parent makefile
130 ///
131 /// This will also remove any preceding comments and up to 1 empty line before the variable.
132 ///
133 /// # Example
134 /// ```
135 /// use makefile_lossless::Makefile;
136 /// let mut makefile: Makefile = "VAR = value\n".parse().unwrap();
137 /// let mut var = makefile.variable_definitions().next().unwrap();
138 /// var.remove();
139 /// assert_eq!(makefile.variable_definitions().count(), 0);
140 /// ```
141 pub fn removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(&mut self) {
142 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent) = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().() {
143 remove_with_preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 lossless/remove_with_preceding_comments().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().(), &parent);
144 }
145 }
146
147 /// Change the assignment operator of this variable definition while preserving everything else
148 /// (export prefix, variable name, value, whitespace, etc.)
149 ///
150 /// # Arguments
151 /// * `op` - The new operator: "=", ":=", "::=", ":::=", "+=", "?=", or "!="
152 ///
153 /// # Example
154 /// ```
155 /// use makefile_lossless::Makefile;
156 /// let mut makefile: Makefile = "VAR := value\n".parse().unwrap();
157 /// let mut var = makefile.variable_definitions().next().unwrap();
158 /// var.set_assignment_operator("?=");
159 /// assert_eq!(var.assignment_operator(), Some("?=".to_string()));
160 /// assert!(makefile.code().contains("VAR ?= value"));
161 /// ```
162 pub fn set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().(&mut self, op: &str) {
163 // Build a new VARIABLE node, copying all children but replacing the OPERATOR token
164 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
165 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(VARIABLErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VARIABLE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
166
167 for child in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
168 match child {
169 rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Tokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Token#(token) if token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# => {
170 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), op);
171 }
172 rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Tokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Token#(token) => {
173 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
174 }
175 rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Noderust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Node#(node) => {
176 rebuild_noderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/rebuild_node().(&mut builder, &node);
177 }
178 }
179 }
180
181 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
182 let new_variable = SyntaxNoderust-analyzer cargo rowan 0.16.1 api/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
183
184 // Replace the old VARIABLE node with the new one
185 let index = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
186 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent) = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().() {
187 parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#index 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, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_variable.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
188
189 // Update self to point to the new node
190 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]cast().(
191 parent
192 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
193 .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(index)
194 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|it| it.into_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_node().())
195 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
196 )
197 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
198 }
199 }
200
201 /// Rename the variable, preserving the operator, value and any
202 /// `export`/`override`/`define` prefix.
203 ///
204 /// The name is the first IDENTIFIER token that is not a directive
205 /// keyword (the same token [`Self::name`] returns). A no-op if the
206 /// definition has no such token.
207 ///
208 /// # Example
209 /// ```
210 /// use makefile_lossless::Makefile;
211 /// let mut makefile: Makefile = "export FOO := bar\n".parse().unwrap();
212 /// let mut var = makefile.variable_definitions().next().unwrap();
213 /// var.set_name("BAZ");
214 /// assert_eq!(var.name(), Some("BAZ".to_string()));
215 /// assert_eq!(makefile.code(), "export BAZ := bar\n");
216 /// ```
217 pub fn set_namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_name().(&mut self, new_name: &str) {
218 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
219 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(VARIABLErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VARIABLE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
220
221 let mut renamed = false;
222 for child in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
223 match child {
224 rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Tokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Token#(token)
225 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().renamed
226 && token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#
227 && token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."export"
228 && token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."override"
229 && token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."define" =>
230 {
231 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), new_name);
232 renamed = true;
233 }
234 rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Tokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Token#(token) => {
235 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
236 }
237 rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Noderust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Node#(node) => {
238 rebuild_noderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/rebuild_node().(&mut builder, &node);
239 }
240 }
241 }
242
243 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
244 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().renamed {
245 return;
246 }
247 let new_variable = SyntaxNoderust-analyzer cargo rowan 0.16.1 api/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
248
249 let index = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
250 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent) = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().() {
251 parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#index 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, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_variable.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
252
253 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]cast().(
254 parent
255 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
256 .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(index)
257 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|it| it.into_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_node().())
258 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
259 )
260 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
261 }
262 }
263
264 /// Remove a trailing whitespace token at the tail of the value, if any.
265 ///
266 /// In GNU Make, whitespace after the last non-comment content but before
267 /// the end of the line (or a `#` comment) is included in the variable's
268 /// value. This is almost always unintentional. This method strips that
269 /// trailing whitespace while preserving everything else (comments,
270 /// nested variable references, line continuations).
271 ///
272 /// Returns `true` if a trailing whitespace token was removed.
273 ///
274 /// # Example
275 /// ```
276 /// use makefile_lossless::Makefile;
277 /// let mut makefile: Makefile = "VAR = value \n".parse().unwrap();
278 /// let mut var = makefile.variable_definitions().next().unwrap();
279 /// assert!(var.trim_trailing_value_whitespace());
280 /// assert_eq!(makefile.code(), "VAR = value\n");
281 /// ```
282 pub fn trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().(&mut self) -> bool {
283 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expr) = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|c| c.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#) else {
284 return false;
285 };
286
287 // Find the last non-comment child. Comments are part of the EXPR but
288 // the whitespace we care about precedes them (Make includes that
289 // whitespace in the value).
290 let last_non_comment = expr
291 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
292 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|c| c.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<L>>`]kind().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#)
293 .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().();
294 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elem) = last_non_comment else {
295 return false;
296 };
297 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = elem.into_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_token().() else {
298 return false;
299 };
300 if token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# {
301 return false;
302 }
303
304 let idx = token.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]index().();
305 expr.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx 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, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
306 true
307 }
308
309 /// Update the value of this variable definition while preserving the rest
310 /// (export prefix, operator, whitespace, etc.)
311 ///
312 /// # Example
313 /// ```
314 /// use makefile_lossless::Makefile;
315 /// let mut makefile: Makefile = "export VAR := old_value\n".parse().unwrap();
316 /// let mut var = makefile.variable_definitions().next().unwrap();
317 /// var.set_value("new_value");
318 /// assert_eq!(var.raw_value(), Some("new_value".to_string()));
319 /// assert!(makefile.code().contains("export VAR := new_value"));
320 /// ```
321 pub fn set_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_value().(&mut self, new_value: &str) {
322 // Find the EXPR node containing the value
323 let expr_index = self
324 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().()
325 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
326 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|it| it.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#)
327 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|it| it.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().());
328
329 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expr_idx) = expr_index {
330 // Build a new EXPR node with the new value
331 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
332 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
333 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), new_value);
334 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
335
336 let new_expr = SyntaxNoderust-analyzer cargo rowan 0.16.1 api/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
337
338 // Replace the old EXPR with the new one
339 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().()
340 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(expr_idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#expr_idx 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, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_expr.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
341 }
342 }
343 }
344
345 #[cfg(test)]
346 mod testsrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/ {
347
348 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#;
349
350 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
351 fn test_variable_parentrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_variable_parent().() {
352 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
353
354 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
355 let parent = var.parentrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]parent().();
356 // Parent is ROOT node which doesn't cast to MakefileItem
357 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parent.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
358 }
359
360 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
361 fn test_assignment_operator_simplerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_assignment_operator_simple().() {
362 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
363 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
364 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
365 }
366
367 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
368 fn test_assignment_operator_recursiverust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_assignment_operator_recursive().() {
369 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR := value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
370 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
371 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(":=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
372 }
373
374 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
375 fn test_assignment_operator_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_assignment_operator_conditional().() {
376 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR ?= value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
377 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
378 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("?=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
379 }
380
381 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
382 fn test_assignment_operator_appendrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_assignment_operator_append().() {
383 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR += value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
384 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
385 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("+=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
386 }
387
388 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
389 fn test_assignment_operator_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_assignment_operator_export().() {
390 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "export VAR := value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
391 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
392 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(":=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
393 }
394
395 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
396 fn test_set_assignment_operator_simple_to_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_assignment_operator_simple_to_conditional().() {
397 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
398 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
399 var.set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().("?=");
400 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("?=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
401 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR ?= value\n");
402 }
403
404 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
405 fn test_set_assignment_operator_recursive_to_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_assignment_operator_recursive_to_conditional().() {
406 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR := value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
407 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
408 var.set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().("?=");
409 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("?=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
410 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR ?= value\n");
411 }
412
413 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
414 fn test_set_assignment_operator_preserves_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_assignment_operator_preserves_export().() {
415 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "export VAR := value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
416 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
417 var.set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().("?=");
418 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("?=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
419 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().());
420 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "export VAR ?= value\n");
421 }
422
423 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
424 fn test_set_assignment_operator_preserves_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_assignment_operator_preserves_whitespace().() {
425 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR := value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
426 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
427 var.set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().("?=");
428 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("?=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
429 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR ?= value\n");
430 }
431
432 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
433 fn test_set_assignment_operator_preserves_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_assignment_operator_preserves_value().() {
434 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR := old_value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
435 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
436 var.set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().("=");
437 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
438 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("old_value".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
439 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = old_value\n");
440 }
441
442 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
443 fn test_set_assignment_operator_to_triple_colonrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_assignment_operator_to_triple_colon().() {
444 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR := value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
445 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
446 var.set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().("::=");
447 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("::=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
448 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR ::= value\n");
449 }
450
451 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
452 fn test_combined_operationsrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_combined_operations().() {
453 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "export VAR := old_value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
454 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
455
456 // Change operator
457 var.set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().("?=");
458 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("?=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
459
460 // Change value
461 var.set_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_value().("new_value");
462 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("new_value".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
463
464 // Verify everything
465 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().());
466 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("VAR".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
467 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "export VAR ?= new_value\n");
468 }
469
470 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
471 fn test_set_name_simplerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_name_simple().() {
472 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR := value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
473 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
474 var.set_namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_name().("RENAMED");
475 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("RENAMED".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
476 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(":=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
477 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("value".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
478 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "RENAMED := value\n");
479 }
480
481 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
482 fn test_set_name_preserves_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_name_preserves_export().() {
483 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "export FOO = nocheck\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
484 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
485 var.set_namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_name().("BAR");
486 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().());
487 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("BAR".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
488 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "export BAR = nocheck\n");
489 }
490
491 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
492 fn test_set_name_preserves_override_and_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_name_preserves_override_and_whitespace().() {
493 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "override FOO := bar\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
494 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
495 var.set_namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_name().("BAZ");
496 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().());
497 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "override BAZ := bar\n");
498 }
499
500 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
501 fn test_set_name_does_not_touch_value_referencerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_name_does_not_touch_value_reference().() {
502 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "FOO := $(FOO) extra\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
503 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
504 var.set_namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_name().("BAR");
505 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "BAR := $(FOO) extra\n");
506 }
507
508 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
509 fn test_override_simplerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_override_simple().() {
510 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "override CC = clang\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
511 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
512 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().());
513 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().var.is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().());
514 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("CC".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
515 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
516 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("clang".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
517 }
518
519 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
520 fn test_override_with_immediate_oprust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_override_with_immediate_op().() {
521 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "override FOO := bar\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
522 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
523 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().());
524 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("FOO".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
525 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(":=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
526 }
527
528 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
529 fn test_override_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_override_export().() {
530 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "override export FOO = bar\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
531 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
532 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().());
533 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().());
534 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("FOO".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
535 }
536
537 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
538 fn test_export_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_export_override().() {
539 // GNU Make accepts either order.
540 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "export override FOO = bar\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
541 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
542 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().());
543 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().());
544 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("FOO".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
545 }
546
547 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
548 fn test_without_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_without_override().() {
549 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "FOO = bar\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
550 let var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
551 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().var.is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().());
552 }
553
554 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
555 fn test_override_in_makefile_with_other_linesrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_override_in_makefile_with_other_lines().() {
556 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "FOO = a\noverride BAR := b\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
557 let vars: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
558 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
559 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vars[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("FOO".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
560 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().vars[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().());
561 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vars[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("BAR".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
562 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(vars[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_overriderust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_override().());
563 }
564
565 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
566 fn test_set_assignment_operator_preserves_shell_callrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_set_assignment_operator_preserves_shell_call().() {
567 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)\n"
568 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
569 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
570 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
571 var.set_assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_assignment_operator().("?=");
572 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var.assignment_operatorrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]assignment_operator().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("?=".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
573 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
574 makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(),
575 "DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)\n"
576 );
577 }
578
579 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
580 fn test_trim_trailing_value_whitespace_single_spacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_single_space().() {
581 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value \n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
582 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
583 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
584 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = value\n");
585 }
586
587 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
588 fn test_trim_trailing_value_whitespace_multiple_spacesrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_multiple_spaces().() {
589 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value \n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
590 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
591 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
592 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = value\n");
593 }
594
595 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
596 fn test_trim_trailing_value_whitespace_tabrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_tab().() {
597 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\t\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
598 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
599 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
600 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = value\n");
601 }
602
603 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
604 fn test_trim_trailing_value_whitespace_nonerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_none().() {
605 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
606 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
607 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().var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
608 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = value\n");
609 }
610
611 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
612 fn test_trim_trailing_value_whitespace_preserves_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_preserves_comment().() {
613 // `VAR = value # comment` sets VAR to "value " — the trailing space
614 // before the `#` is part of the value. Trimming should strip just that.
615 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value # comment\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
616 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
617 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
618 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = value# comment\n");
619 }
620
621 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
622 fn test_trim_trailing_value_whitespace_preserves_internal_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_preserves_internal_whitespace().() {
623 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = foo bar \n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
624 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
625 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
626 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = foo bar\n");
627 }
628
629 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
630 fn test_trim_trailing_value_whitespace_with_var_refrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_with_var_ref().() {
631 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = $(BAR) \n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
632 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
633 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
634 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = $(BAR)\n");
635 }
636
637 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
638 fn test_trim_trailing_value_whitespace_empty_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_empty_value().() {
639 // `VAR = ` has an empty EXPR; the whitespace is between OPERATOR and
640 // NEWLINE, not part of the value.
641 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = \n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
642 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
643 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().var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
644 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = \n");
645 }
646
647 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
648 fn test_trim_trailing_value_whitespace_line_continuationrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/tests/test_trim_trailing_value_whitespace_line_continuation().() {
649 // The last token in EXPR is BACKSLASH, not WHITESPACE — don't trim.
650 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = foo \\\n\tbar\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
651 let mut var = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
652 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().var.trim_trailing_value_whitespacerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]trim_trailing_value_whitespace().());
653 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), "VAR = foo \\\n\tbar\n");
654 }
655 }