| 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()., Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#, ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#, Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#, ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#}; |
| 3 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::{EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#, IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#}; |
| 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 | impl Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include# { |
| 8 | /// Get the raw path of the include directive |
| 9 | pub fn pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path().(&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#> { |
| 10 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().() |
| 11 | .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().() |
| 12 | .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#) |
| 13 | .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().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 14 | } |
| 15 | |
| 16 | /// Get the text range of the path portion of the include directive. |
| 17 | /// |
| 18 | /// # Example |
| 19 | /// ``` |
| 20 | /// use makefile_lossless::Makefile; |
| 21 | /// let makefile: Makefile = "include config.mk\n".parse().unwrap(); |
| 22 | /// let inc = makefile.includes().next().unwrap(); |
| 23 | /// let range = inc.path_range().unwrap(); |
| 24 | /// assert_eq!(&makefile.to_string()[std::ops::Range::from(range)], "config.mk"); |
| 25 | /// ``` |
| 26 | pub fn path_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path_range().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#> { |
| 27 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().() |
| 28 | .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().() |
| 29 | .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#) |
| 30 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|it| it.text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().()) |
| 31 | } |
| 32 | |
| 33 | /// Check if this is an optional include (-include or sinclude) |
| 34 | pub fn is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().(&self) -> bool { |
| 35 | let text = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().().textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text().(); |
| 36 | text.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("-include") || text.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("sinclude") |
| 37 | } |
| 38 | |
| 39 | /// Get the parent item of this include directive, if any |
| 40 | /// |
| 41 | /// Returns `Some(MakefileItem)` if this include has a parent that is a MakefileItem |
| 42 | /// (e.g., a Conditional), or `None` if the parent is the root Makefile node. |
| 43 | /// |
| 44 | /// # Example |
| 45 | /// ``` |
| 46 | /// use makefile_lossless::Makefile; |
| 47 | /// |
| 48 | /// let makefile: Makefile = r#"ifdef DEBUG |
| 49 | /// include debug.mk |
| 50 | /// endif |
| 51 | /// "#.parse().unwrap(); |
| 52 | /// let cond = makefile.conditionals().next().unwrap(); |
| 53 | /// let inc = cond.if_items().next().unwrap(); |
| 54 | /// // Include's parent is the conditional |
| 55 | /// assert!(matches!(inc, makefile_lossless::MakefileItem::Include(_))); |
| 56 | /// ``` |
| 57 | pub fn parentrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]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#> { |
| 58 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][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().) |
| 59 | } |
| 60 | |
| 61 | /// Remove this include directive from the makefile |
| 62 | /// |
| 63 | /// This will also remove any preceding comments. |
| 64 | /// |
| 65 | /// # Example |
| 66 | /// ``` |
| 67 | /// use makefile_lossless::Makefile; |
| 68 | /// let mut makefile: Makefile = "include config.mk\nVAR = value\n".parse().unwrap(); |
| 69 | /// let mut inc = makefile.includes().next().unwrap(); |
| 70 | /// inc.remove().unwrap(); |
| 71 | /// assert_eq!(makefile.includes().count(), 0); |
| 72 | /// ``` |
| 73 | pub fn removerust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]remove().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> { |
| 74 | 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#[Include][AstNode]syntax().().parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().() else { |
| 75 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# { |
| 76 | errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# { |
| 77 | messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "Cannot remove include: no parent node".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 78 | linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1, |
| 79 | contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "include_remove".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 80 | }], |
| 81 | })); |
| 82 | }; |
| 83 | |
| 84 | 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#[Include][AstNode]syntax().(), &parent); |
| 85 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 86 | } |
| 87 | |
| 88 | /// Set the path of this include directive |
| 89 | /// |
| 90 | /// # Example |
| 91 | /// ``` |
| 92 | /// use makefile_lossless::Makefile; |
| 93 | /// let mut makefile: Makefile = "include old.mk\n".parse().unwrap(); |
| 94 | /// let mut inc = makefile.includes().next().unwrap(); |
| 95 | /// inc.set_path("new.mk"); |
| 96 | /// assert_eq!(inc.path(), Some("new.mk".to_string())); |
| 97 | /// assert_eq!(makefile.to_string(), "include new.mk\n"); |
| 98 | /// ``` |
| 99 | pub fn set_pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_path().(&mut self, new_path: &str) { |
| 100 | // Find the EXPR node containing the path |
| 101 | let expr_index = self |
| 102 | .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().() |
| 103 | .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().() |
| 104 | .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#) |
| 105 | .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().()); |
| 106 | |
| 107 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expr_idx) = expr_index { |
| 108 | // Build a new EXPR node with the new path |
| 109 | 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().(); |
| 110 | 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().()); |
| 111 | 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_path); |
| 112 | builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 113 | |
| 114 | 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().()); |
| 115 | |
| 116 | // Replace the old EXPR with the new one |
| 117 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().() |
| 118 | .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().()]); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /// Make this include optional (change "include" to "-include") |
| 123 | /// |
| 124 | /// If the include is already optional, this has no effect. |
| 125 | /// |
| 126 | /// # Example |
| 127 | /// ``` |
| 128 | /// use makefile_lossless::Makefile; |
| 129 | /// let mut makefile: Makefile = "include config.mk\n".parse().unwrap(); |
| 130 | /// let mut inc = makefile.includes().next().unwrap(); |
| 131 | /// inc.set_optional(true); |
| 132 | /// assert!(inc.is_optional()); |
| 133 | /// assert_eq!(makefile.to_string(), "-include config.mk\n"); |
| 134 | /// ``` |
| 135 | pub fn set_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_optional().(&mut self, optional: bool) { |
| 136 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::INCLUDErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INCLUDE#; |
| 137 | |
| 138 | // Find the first IDENTIFIER token (which is the include keyword) |
| 139 | let keyword_token = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|it| { |
| 140 | it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() |
| 141 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|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#) |
| 142 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false) |
| 143 | }); |
| 144 | |
| 145 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token_element) = keyword_token { |
| 146 | let token = token_element.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 147 | let current_text = token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().(); |
| 148 | |
| 149 | let new_keyword = if optional { |
| 150 | // Make it optional |
| 151 | if current_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()."include" { |
| 152 | "-include" |
| 153 | } else if current_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()."sinclude" || current_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()."-include" { |
| 154 | // Already optional, no change needed |
| 155 | return; |
| 156 | } else { |
| 157 | // Shouldn't happen, but handle gracefully |
| 158 | return; |
| 159 | } |
| 160 | } else { |
| 161 | // Make it non-optional |
| 162 | if current_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()."-include" || current_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()."sinclude" { |
| 163 | "include" |
| 164 | } else if current_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()."include" { |
| 165 | // Already non-optional, no change needed |
| 166 | return; |
| 167 | } else { |
| 168 | // Shouldn't happen, but handle gracefully |
| 169 | return; |
| 170 | } |
| 171 | }; |
| 172 | |
| 173 | // Rebuild the entire INCLUDE node, replacing just the keyword token |
| 174 | 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().(); |
| 175 | builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(INCLUDErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INCLUDE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 176 | |
| 177 | for child in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() { |
| 178 | match child { |
| 179 | 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#(tok) |
| 180 | if tok.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# && tok.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().current_text => |
| 181 | { |
| 182 | // Replace the include keyword |
| 183 | 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_keyword); |
| 184 | } |
| 185 | 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#(tok) => { |
| 186 | // Copy other tokens as-is |
| 187 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(tok.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().(), tok.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().()); |
| 188 | } |
| 189 | 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) => { |
| 190 | // For nodes (like EXPR), rebuild them |
| 191 | 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().()); |
| 192 | for node_child in node.children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() { |
| 193 | if let 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#(tok) = node_child { |
| 194 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(tok.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().(), tok.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().()); |
| 195 | } |
| 196 | } |
| 197 | builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 203 | let new_include = 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().()); |
| 204 | |
| 205 | // Replace the old INCLUDE node with the new one |
| 206 | let index = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().().indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().(); |
| 207 | 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#[Include][AstNode]syntax().().parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().() { |
| 208 | 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_include.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().()]); |
| 209 | |
| 210 | // Update self to point to the new node |
| 211 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]cast().( |
| 212 | parent |
| 213 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 214 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(index) |
| 215 | .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().()) |
| 216 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 217 | ) |
| 218 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | #[cfg(test)] |
| 225 | mod testsrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/ { |
| 226 | |
| 227 | 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#; |
| 228 | |
| 229 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 230 | fn test_include_parentrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_parent().() { |
| 231 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include common.mk\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().(); |
| 232 | |
| 233 | let inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 234 | let parent = inc.parentrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]parent().(); |
| 235 | // Parent is ROOT node which doesn't cast to MakefileItem |
| 236 | 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().()); |
| 237 | } |
| 238 | |
| 239 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 240 | fn test_add_includerust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_add_include().() { |
| 241 | let mut makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]new().(); |
| 242 | makefile.add_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_include().("config.mk"); |
| 243 | |
| 244 | let includes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 245 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(includes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 246 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(includes[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()..pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("config.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 247 | |
| 248 | let files: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.included_filesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]included_files().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 249 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(files, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["config.mk"]); |
| 250 | |
| 251 | // Check the generated text |
| 252 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "include config.mk\n"); |
| 253 | } |
| 254 | |
| 255 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 256 | fn test_add_include_to_existingrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_add_include_to_existing().() { |
| 257 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\nrule:\n\tcommand\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().(); |
| 258 | makefile.add_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_include().("config.mk"); |
| 259 | |
| 260 | // Include should be added at the beginning |
| 261 | let files: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.included_filesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]included_files().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 262 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(files, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["config.mk"]); |
| 263 | |
| 264 | // Check that the include comes first |
| 265 | let text = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 266 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(text.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("include config.mk\n")); |
| 267 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(text.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = value")); |
| 268 | } |
| 269 | |
| 270 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 271 | fn test_insert_includerust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_insert_include().() { |
| 272 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\nrule:\n\tcommand\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().(); |
| 273 | makefile.insert_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_include().(1, "config.mk").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 274 | |
| 275 | let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 276 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3); |
| 277 | |
| 278 | // Check the middle item is the include |
| 279 | let files: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.included_filesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]included_files().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 280 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(files, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["config.mk"]); |
| 281 | } |
| 282 | |
| 283 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 284 | fn test_insert_include_at_beginningrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_insert_include_at_beginning().() { |
| 285 | let mut 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().(); |
| 286 | makefile.insert_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_include().(0, "config.mk").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 287 | |
| 288 | let text = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 289 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(text.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("include config.mk\n")); |
| 290 | } |
| 291 | |
| 292 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 293 | fn test_insert_include_at_endrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_insert_include_at_end().() { |
| 294 | let mut 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().(); |
| 295 | let item_count = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(); |
| 296 | makefile.insert_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_include().(item_count, "config.mk").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 297 | |
| 298 | let text = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 299 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(text.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().("include config.mk\n")); |
| 300 | } |
| 301 | |
| 302 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 303 | fn test_insert_include_out_of_boundsrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_insert_include_out_of_bounds().() { |
| 304 | let mut 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().(); |
| 305 | let result = makefile.insert_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_include().(100, "config.mk"); |
| 306 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 307 | } |
| 308 | |
| 309 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 310 | fn test_insert_include_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_insert_include_after().() { |
| 311 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = value1\nVAR2 = value2\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().(); |
| 312 | let first_var = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 313 | makefile |
| 314 | .insert_include_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_include_after().(&first_var, "config.mk") |
| 315 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 316 | |
| 317 | let files: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.included_filesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]included_files().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 318 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(files, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["config.mk"]); |
| 319 | |
| 320 | // Check that the include is after VAR1 |
| 321 | let text = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 322 | let var1_pos = text.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().("VAR1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 323 | let include_pos = text.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().("include config.mk").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 324 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(include_pos >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). var1_pos); |
| 325 | } |
| 326 | |
| 327 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 328 | fn test_insert_include_after_with_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_insert_include_after_with_rule().() { |
| 329 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\nrule2:\n\tcommand2\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().(); |
| 330 | let first_rule_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 331 | makefile |
| 332 | .insert_include_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_include_after().(&first_rule_item, "config.mk") |
| 333 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 334 | |
| 335 | let text = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 336 | let rule1_pos = text.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().("rule1:").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 337 | let include_pos = text.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().("include config.mk").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 338 | let rule2_pos = text.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().("rule2:").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 339 | |
| 340 | // Include should be between rule1 and rule2 |
| 341 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(include_pos >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rule1_pos); |
| 342 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(include_pos <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rule2_pos); |
| 343 | } |
| 344 | |
| 345 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 346 | fn test_include_removerust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_remove().() { |
| 347 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include config.mk\nVAR = 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().(); |
| 348 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 349 | inc.removerust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]remove().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 350 | |
| 351 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 352 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "VAR = value\n"); |
| 353 | } |
| 354 | |
| 355 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 356 | fn test_include_remove_multiplerust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_remove_multiple().() { |
| 357 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include first.mk\ninclude second.mk\nVAR = value\n" |
| 358 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 359 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 360 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 361 | inc.removerust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]remove().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 362 | |
| 363 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 364 | let remaining = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 365 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(remaining.pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("second.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 366 | } |
| 367 | |
| 368 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 369 | fn test_include_set_pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_set_path().() { |
| 370 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include old.mk\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().(); |
| 371 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 372 | inc.set_pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_path().("new.mk"); |
| 373 | |
| 374 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(inc.pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("new.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 375 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "include new.mk\n"); |
| 376 | } |
| 377 | |
| 378 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 379 | fn test_include_set_path_preserves_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_set_path_preserves_optional().() { |
| 380 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "-include old.mk\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().(); |
| 381 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 382 | inc.set_pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_path().("new.mk"); |
| 383 | |
| 384 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(inc.pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("new.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 385 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(inc.is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); |
| 386 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "-include new.mk\n"); |
| 387 | } |
| 388 | |
| 389 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 390 | fn test_include_set_optional_truerust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_set_optional_true().() { |
| 391 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include config.mk\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().(); |
| 392 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 393 | inc.set_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_optional().(true); |
| 394 | |
| 395 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(inc.is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); |
| 396 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "-include config.mk\n"); |
| 397 | } |
| 398 | |
| 399 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 400 | fn test_include_set_optional_falserust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_set_optional_false().() { |
| 401 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "-include config.mk\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().(); |
| 402 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 403 | inc.set_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_optional().(false); |
| 404 | |
| 405 | 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().inc.is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); |
| 406 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "include config.mk\n"); |
| 407 | } |
| 408 | |
| 409 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 410 | fn test_include_set_optional_from_sincluderust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_set_optional_from_sinclude().() { |
| 411 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "sinclude config.mk\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().(); |
| 412 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 413 | inc.set_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_optional().(false); |
| 414 | |
| 415 | 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().inc.is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); |
| 416 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "include config.mk\n"); |
| 417 | } |
| 418 | |
| 419 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 420 | fn test_include_set_optional_already_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_set_optional_already_optional().() { |
| 421 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "-include config.mk\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().(); |
| 422 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 423 | inc.set_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_optional().(true); |
| 424 | |
| 425 | // Should remain unchanged |
| 426 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(inc.is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); |
| 427 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "-include config.mk\n"); |
| 428 | } |
| 429 | |
| 430 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 431 | fn test_include_set_optional_already_non_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_set_optional_already_non_optional().() { |
| 432 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include config.mk\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().(); |
| 433 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 434 | inc.set_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_optional().(false); |
| 435 | |
| 436 | // Should remain unchanged |
| 437 | 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().inc.is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); |
| 438 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "include config.mk\n"); |
| 439 | } |
| 440 | |
| 441 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 442 | fn test_include_combined_operationsrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_combined_operations().() { |
| 443 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include old.mk\nVAR = 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().(); |
| 444 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 445 | |
| 446 | // Change path and make optional |
| 447 | inc.set_pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_path().("new.mk"); |
| 448 | inc.set_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]set_optional().(true); |
| 449 | |
| 450 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(inc.pathrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("new.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 451 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(inc.is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); |
| 452 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "-include new.mk\nVAR = value\n"); |
| 453 | } |
| 454 | |
| 455 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 456 | fn test_include_path_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_path_range().() { |
| 457 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include config.mk\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().(); |
| 458 | let inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 459 | let range = inc.path_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path_range().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 460 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 461 | &makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#::fromrust-analyzer cargo text-size 1.1.1 range/impl#[`Range<T>`][`From<TextRange>`]from().(range)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 462 | "config.mk" |
| 463 | ); |
| 464 | } |
| 465 | |
| 466 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 467 | fn test_include_path_range_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_path_range_optional().() { |
| 468 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "-include optional.mk\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().(); |
| 469 | let inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 470 | let range = inc.path_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path_range().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 471 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 472 | &makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#::fromrust-analyzer cargo text-size 1.1.1 range/impl#[`Range<T>`][`From<TextRange>`]from().(range)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 473 | "optional.mk" |
| 474 | ); |
| 475 | } |
| 476 | |
| 477 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 478 | fn test_include_path_range_sincluderust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_path_range_sinclude().() { |
| 479 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "sinclude silent.mk\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().(); |
| 480 | let inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 481 | let range = inc.path_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]path_range().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 482 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 483 | &makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#::fromrust-analyzer cargo text-size 1.1.1 range/impl#[`Range<T>`][`From<TextRange>`]from().(range)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 484 | "silent.mk" |
| 485 | ); |
| 486 | } |
| 487 | |
| 488 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 489 | fn test_include_with_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/include/tests/test_include_with_comment().() { |
| 490 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# Comment\ninclude config.mk\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().(); |
| 491 | let mut inc = makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 492 | inc.removerust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]remove().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 493 | |
| 494 | // Comment should also be removed |
| 495 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 496 | 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().makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("# Comment")); |
| 497 | } |
| 498 | } |