| 1 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::lexrust-analyzer cargo makefile-lossless 0.3.40 lex/::lexrust-analyzer cargo makefile-lossless 0.3.40 lex/lex().; |
| 2 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::MakefileVariantrust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#; |
| 3 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#; |
| 4 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::*; |
| 5 | 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#; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 7 | |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 9 | /// An error that can occur when parsing a makefile |
| 10 | pub enum Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error# { |
| 11 | /// An I/O error occurred |
| 12 | Iorust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Io#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 13 | |
| 14 | /// A parse error occurred |
| 15 | Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#), |
| 16 | } |
| 17 | |
| 18 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error# { |
| 19 | fn fmtrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Error][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 20 | match &self { |
| 21 | Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Iorust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Io#(e) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "IO error: {}", e), |
| 22 | Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(e) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Parse error: {}", e), |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> for Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error# { |
| 28 | fn fromrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Error][`From<std::io::Error>`]from().(e: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#) -> Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Error][`From<std::io::Error>`] { |
| 29 | Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Iorust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Io#(e) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error# {} |
| 34 | |
| 35 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 36 | /// An error that occurred while parsing a makefile |
| 37 | pub struct ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# { |
| 38 | /// The list of individual parsing errors |
| 39 | pub errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#>, |
| 40 | } |
| 41 | |
| 42 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 43 | /// Information about a specific parsing error |
| 44 | pub struct ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# { |
| 45 | /// The error message |
| 46 | pub messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 47 | /// The line number where the error occurred |
| 48 | pub linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: usize, |
| 49 | /// The context around the error |
| 50 | pub contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 51 | } |
| 52 | |
| 53 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# { |
| 54 | fn fmtrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[ParseError][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 55 | for err in &self.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors. { |
| 56 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f, "Error at line {}: {}", err.linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line., err.messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 57 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f, "{}| {}", err.linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line., err.contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 58 | } |
| 59 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {} |
| 64 | |
| 65 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#> for Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error# { |
| 66 | fn fromrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Error][`From<ParseError>`]from().(e: ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#) -> Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Error][`From<ParseError>`] { |
| 67 | Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(e) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /// A positioned parse error containing location information. |
| 72 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 73 | pub struct PositionedParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError# { |
| 74 | /// The error message |
| 75 | pub messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#message.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 76 | /// The text range where the error occurred |
| 77 | pub rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#range.: rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#, |
| 78 | /// Optional error code for categorization |
| 79 | pub coderust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#code.: 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#>, |
| 80 | } |
| 81 | |
| 82 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for PositionedParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError# { |
| 83 | fn fmtrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[PositionedParseError][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 84 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#message.) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for PositionedParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError# {} |
| 89 | |
| 90 | /// these two SyntaxKind types, allowing for a nicer SyntaxNode API where |
| 91 | /// "kinds" are values from our `enum SyntaxKind`, instead of plain u16 values. |
| 92 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 93 | pub enum Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang# {} |
| 94 | impl rowanrust-analyzer cargo rowan 0.16.1 crate/::Languagerust-analyzer cargo rowan 0.16.1 api/Language# for Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang# { |
| 95 | type Kindrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Lang][Language]Kind# = SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#; |
| 96 | fn kind_from_rawrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Lang][Language]kind_from_raw().(raw: rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxKindrust-analyzer cargo rowan 0.16.1 green/SyntaxKind#) -> Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Lang][Language]::Kindrust-analyzer cargo rowan 0.16.1 api/Language#Kind# { |
| 97 | unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().::<u16, SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#>(raw.0rust-analyzer cargo rowan 0.16.1 green/SyntaxKind#0.) } |
| 98 | } |
| 99 | fn kind_to_rawrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Lang][Language]kind_to_raw().(kind: Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Lang][Language]::Kindrust-analyzer cargo rowan 0.16.1 api/Language#Kind#) -> rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxKindrust-analyzer cargo rowan 0.16.1 green/SyntaxKind# { |
| 100 | kind.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /// GreenNode is an immutable tree, which is cheap to change, |
| 105 | /// but doesn't contain offsets and parent pointers. |
| 106 | use rowanrust-analyzer cargo rowan 0.16.1 crate/::GreenNoderust-analyzer cargo rowan 0.16.1 green/node/GreenNode#; |
| 107 | |
| 108 | /// You can construct GreenNodes by hand, but a builder |
| 109 | /// is helpful for top-down parsers: it maintains a stack |
| 110 | /// of currently in-progress nodes |
| 111 | use rowanrust-analyzer cargo rowan 0.16.1 crate/::GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#; |
| 112 | |
| 113 | /// The parse results are stored as a "green tree". |
| 114 | /// We'll discuss working with the results later |
| 115 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 116 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) struct Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse# { |
| 117 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) green_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#green_node.: GreenNoderust-analyzer cargo rowan 0.16.1 green/node/GreenNode#, |
| 118 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#>, |
| 119 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) positioned_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#positioned_errors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<PositionedParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#>, |
| 120 | } |
| 121 | |
| 122 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) fn parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(text: &str, variant: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MakefileVariantrust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#>) -> Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse# { |
| 123 | struct Parserrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser# { |
| 124 | /// input tokens, including whitespace, |
| 125 | /// in *reverse* order. |
| 126 | tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)>, |
| 127 | /// the in-progress tree. |
| 128 | builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder.: GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#<'static>, |
| 129 | /// the list of syntax errors we've accumulated |
| 130 | /// so far. |
| 131 | errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#errors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#>, |
| 132 | /// positioned errors with location information |
| 133 | positioned_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#positioned_errors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<PositionedParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#>, |
| 134 | /// Token positions (start, end) in forward order, indexed by forward token index |
| 135 | token_positionsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#token_positions.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#, rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#)>, |
| 136 | /// current token index into token_positions (counting from the end since tokens are in reverse) |
| 137 | current_token_indexrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#current_token_index.: usize, |
| 138 | /// The original text |
| 139 | original_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#original_text.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 140 | /// The makefile variant |
| 141 | variantrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#variant.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MakefileVariantrust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#>, |
| 142 | /// Parity of the current run of bumped BACKSLASH tokens: true once an |
| 143 | /// odd number have been seen, meaning the next backslash is escaped |
| 144 | /// (`\\`) and a following newline is a literal backslash, not a line |
| 145 | /// continuation. Reset to false by any other token. Mirrors the lexer's |
| 146 | /// `prev_was_backslash`, which makes the same decision for tokenizing |
| 147 | /// the continued line's indent. |
| 148 | pending_backslash_escaperust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#pending_backslash_escape.: bool, |
| 149 | } |
| 150 | |
| 151 | impl Parserrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser# { |
| 152 | fn errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().(&mut self, msg: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) { |
| 153 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(ERRORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ERROR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 154 | |
| 155 | let (line, context) = if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) { |
| 156 | // For indented lines, report the error on the next line |
| 157 | let lines: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = self.original_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#original_text..linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 158 | let tab_line = lines |
| 159 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 160 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 161 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|(_, line)| line.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('\t')) |
| 162 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(i, _)| i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1) |
| 163 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(1); |
| 164 | |
| 165 | // Use the next line as context if available |
| 166 | let next_line = tab_line 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; |
| 167 | if next_line rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().lines.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 168 | (next_line, lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().next_line rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 169 | } else { |
| 170 | (tab_line, lines[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().tab_line rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 171 | } |
| 172 | } else { |
| 173 | let line = self.get_line_number_for_positionrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]get_line_number_for_position().(self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 174 | (line, self.get_context_for_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]get_context_for_line().(line)) |
| 175 | }; |
| 176 | |
| 177 | let message = if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().msg.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("indented") { |
| 178 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() && self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..0 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# { |
| 179 | "expected ':'".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 180 | } else { |
| 181 | "indented line not part of a rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 182 | } |
| 183 | } else { |
| 184 | msg |
| 185 | }; |
| 186 | |
| 187 | self.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#errors..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# { |
| 188 | messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: message.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), |
| 189 | linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line., |
| 190 | contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context., |
| 191 | }); |
| 192 | |
| 193 | self.add_positioned_errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]add_positioned_error().(message, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 194 | |
| 195 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 196 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 197 | } |
| 198 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 199 | } |
| 200 | |
| 201 | /// Add a positioned error at the current token position |
| 202 | fn add_positioned_errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]add_positioned_error().(&mut self, message: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, code: 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#>) { |
| 203 | let range = if self.current_token_indexrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#current_token_index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.token_positionsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#token_positions..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 204 | let (start, end) = self.token_positionsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#token_positions.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.current_token_indexrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#current_token_index.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 205 | rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(start, end) |
| 206 | } else { |
| 207 | // Default to end of text if no current token |
| 208 | let end = self |
| 209 | .token_positionsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#token_positions. |
| 210 | .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().() |
| 211 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(_, end)| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().end) |
| 212 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#::fromrust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`From<u32>`]from().(0)); |
| 213 | rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(end, end) |
| 214 | }; |
| 215 | |
| 216 | self.positioned_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#positioned_errors..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(PositionedParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError# { |
| 217 | messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#message., |
| 218 | rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#range., |
| 219 | coderust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#code., |
| 220 | }); |
| 221 | } |
| 222 | |
| 223 | fn get_line_number_for_positionrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]get_line_number_for_position().(&self, position: usize) -> usize { |
| 224 | if position rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 225 | return self.original_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#original_text..matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]matches().('\n').countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() 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; |
| 226 | } |
| 227 | |
| 228 | // Count newlines in the processed text up to this position |
| 229 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#position]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 230 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 231 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|(kind, _)| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().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().NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) |
| 232 | .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().() |
| 233 | +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 |
| 234 | } |
| 235 | |
| 236 | fn get_context_for_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]get_context_for_line().(&self, line_number: usize) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 237 | self.original_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#original_text. |
| 238 | .linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() |
| 239 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(line_number rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1) |
| 240 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("") |
| 241 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 242 | } |
| 243 | |
| 244 | fn parse_recipe_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_recipe_line().(&mut self) { |
| 245 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 246 | |
| 247 | // Check for and consume the indent |
| 248 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) { |
| 249 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("recipe line must start with a tab".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 250 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 251 | return; |
| 252 | } |
| 253 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 254 | |
| 255 | // Parse the recipe content, handling line continuations (backslash at end of line) |
| 256 | loop { |
| 257 | let mut last_text_content: 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#> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 258 | |
| 259 | // Consume all tokens until newline, tracking the last TEXT token's content |
| 260 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 261 | // Save the text content if this is a TEXT token |
| 262 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#) { |
| 263 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_kind, text)) = self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().() { |
| 264 | last_text_content = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(text.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()); |
| 265 | } |
| 266 | } |
| 267 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 268 | } |
| 269 | |
| 270 | // Consume the newline |
| 271 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 272 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 273 | } |
| 274 | |
| 275 | // Check if the last TEXT token ended with a backslash (continuation) |
| 276 | let is_continuation = last_text_content |
| 277 | .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 278 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|text| text.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().().ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\\')) |
| 279 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false); |
| 280 | |
| 281 | if is_continuation { |
| 282 | // This is a continuation line - consume the indent of the next line and continue |
| 283 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) { |
| 284 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 285 | // Continue parsing the next line |
| 286 | continue; |
| 287 | } else { |
| 288 | // If there's no indent after a backslash, that's unusual but we'll stop here |
| 289 | break; |
| 290 | } |
| 291 | } else { |
| 292 | // No continuation - we're done |
| 293 | break; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 298 | } |
| 299 | |
| 300 | fn parse_rule_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_target().(&mut self) -> bool { |
| 301 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 302 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) => { |
| 303 | // Check if this is an archive member (e.g., libfoo.a(bar.o)) |
| 304 | if self.is_archive_memberrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_archive_member().() { |
| 305 | self.parse_archive_memberrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_archive_member().(); |
| 306 | } else { |
| 307 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 308 | } |
| 309 | true |
| 310 | } |
| 311 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => { |
| 312 | self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(); |
| 313 | true |
| 314 | } |
| 315 | _ => { |
| 316 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected rule target".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 317 | false |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | fn is_archive_memberrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_archive_member().(&self) -> bool { |
| 323 | // Check if the current identifier is followed by a parenthesis |
| 324 | // Pattern: archive.a(member.o) |
| 325 | if self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().2 { |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | // Look for pattern: IDENTIFIER LPAREN |
| 330 | let current_is_identifier = self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#); |
| 331 | let next_is_lparen = |
| 332 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 && self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..0 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().LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN#; |
| 333 | |
| 334 | current_is_identifier && next_is_lparen |
| 335 | } |
| 336 | |
| 337 | fn parse_archive_memberrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_archive_member().(&mut self) { |
| 338 | // We're parsing something like: libfoo.a(bar.o baz.o) |
| 339 | // Structure will be: |
| 340 | // - IDENTIFIER: libfoo.a |
| 341 | // - LPAREN |
| 342 | // - ARCHIVE_MEMBERS |
| 343 | // - ARCHIVE_MEMBER: bar.o |
| 344 | // - ARCHIVE_MEMBER: baz.o |
| 345 | // - RPAREN |
| 346 | |
| 347 | // Parse archive name |
| 348 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) { |
| 349 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 350 | } |
| 351 | |
| 352 | // Parse opening parenthesis |
| 353 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN#) { |
| 354 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 355 | |
| 356 | // Start the ARCHIVE_MEMBERS container for just the members |
| 357 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(ARCHIVE_MEMBERSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBERS#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 358 | |
| 359 | // Parse member name(s) - each as an ARCHIVE_MEMBER node |
| 360 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN#) { |
| 361 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 362 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#) => { |
| 363 | // Start an individual member node |
| 364 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(ARCHIVE_MEMBERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 365 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 366 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 367 | } |
| 368 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) => self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(), |
| 369 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => { |
| 370 | // Variable reference can also be a member |
| 371 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(ARCHIVE_MEMBERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 372 | self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(); |
| 373 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 374 | } |
| 375 | _ => break, |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | // Finish the ARCHIVE_MEMBERS container |
| 380 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 381 | |
| 382 | // Parse closing parenthesis |
| 383 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN#) { |
| 384 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 385 | } else { |
| 386 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected ')' to close archive member".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | fn parse_rule_dependenciesrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_dependencies().(&mut self) { |
| 392 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITES#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 393 | |
| 394 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 395 | // The prerequisite list may continue on the next physical line. |
| 396 | if self.consume_line_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]consume_line_continuation().() { |
| 397 | continue; |
| 398 | } |
| 399 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 400 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) => { |
| 401 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume whitespace between prerequisites |
| 402 | } |
| 403 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) => { |
| 404 | // Trailing comment ends the prerequisite list. |
| 405 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 406 | } |
| 407 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => { |
| 408 | // Collect contiguous non-whitespace tokens into one |
| 409 | // PREREQUISITE node, preserving structures like |
| 410 | // `$$(@:.out=.src)` or `lib(member.o)` as a single |
| 411 | // word. |
| 412 | self.parse_prerequisite_wordrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_prerequisite_word().(); |
| 413 | } |
| 414 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => break, |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // End PREREQUISITES |
| 419 | } |
| 420 | |
| 421 | /// Parse a single prerequisite word: consume tokens up to the next |
| 422 | /// whitespace/newline/comment, descending into variable references |
| 423 | /// (`$(...)`, `${...}`, `$X`, `$$`) and archive-member parentheses |
| 424 | /// without treating them as word boundaries. |
| 425 | fn parse_prerequisite_wordrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_prerequisite_word().(&mut self) { |
| 426 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(PREREQUISITErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 427 | |
| 428 | // Archive member syntax: `lib(member.o)` — keep as a unit. |
| 429 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) && self.is_archive_memberrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_archive_member().() { |
| 430 | self.parse_archive_memberrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_archive_member().(); |
| 431 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | // Otherwise, consume tokens until a separator. A line continuation |
| 436 | // ends the word; the outer loop consumes it and resumes on the |
| 437 | // next physical line. |
| 438 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(kind) = self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 439 | match kind { |
| 440 | WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# | NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# | COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# => break, |
| 441 | BACKSLASHrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BACKSLASH# if self.is_line_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_line_continuation().() => break, |
| 442 | DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR# => self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(), |
| 443 | _ => self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(), |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // End PREREQUISITE |
| 448 | } |
| 449 | |
| 450 | fn parse_rule_recipesrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_recipes().(&mut self) { |
| 451 | // Track how many levels deep we are in conditionals that started in this rule |
| 452 | let mut conditional_depth = 0; |
| 453 | // Also track consecutive newlines to detect blank lines |
| 454 | let mut newline_count = 0; |
| 455 | |
| 456 | loop { |
| 457 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 458 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) => { |
| 459 | newline_count = 0; |
| 460 | self.parse_recipe_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_recipe_line().(); |
| 461 | } |
| 462 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) => { |
| 463 | newline_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 464 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 465 | } |
| 466 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) => { |
| 467 | // Comments after blank lines should not be part of the rule |
| 468 | if conditional_depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 && newline_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().1 { |
| 469 | break; |
| 470 | } |
| 471 | newline_count = 0; |
| 472 | self.parse_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_comment().(); |
| 473 | } |
| 474 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) => { |
| 475 | let token = &self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(); |
| 476 | // Check if this is a starting conditional directive |
| 477 | if Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]::is_conditional_startrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_conditional_start().(token) |
| 478 | && matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.variantrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#variant., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileVariantrust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#::GNUMakerust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#GNUMake#)) |
| 479 | { |
| 480 | // If we're not inside a conditional (depth == 0) and there's a blank line, |
| 481 | // this is a top-level conditional, not part of the rule |
| 482 | if conditional_depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 && newline_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().1 { |
| 483 | break; |
| 484 | } |
| 485 | newline_count = 0; |
| 486 | conditional_depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 487 | self.parse_conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_conditional().(); |
| 488 | // parse_conditional() handles the entire conditional including endif, |
| 489 | // so we need to decrement after it returns |
| 490 | conditional_depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1; |
| 491 | } else if token 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" || token 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" || token 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" { |
| 492 | // Includes can appear in rules, with same blank line logic |
| 493 | if conditional_depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 && newline_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().1 { |
| 494 | break; |
| 495 | } |
| 496 | newline_count = 0; |
| 497 | self.parse_includerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_include().(); |
| 498 | } else if token 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()."else" || token 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()."endif" { |
| 499 | // These should only appear if we're inside a conditional |
| 500 | // If we see them at depth 0, something is wrong, so break |
| 501 | break; |
| 502 | } else { |
| 503 | // Any other identifier at depth 0 means the rule is over |
| 504 | if conditional_depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 { |
| 505 | break; |
| 506 | } |
| 507 | // Otherwise, it's content inside a conditional (variable assignment, etc.) |
| 508 | // Let it be handled by parse_normal_content |
| 509 | break; |
| 510 | } |
| 511 | } |
| 512 | _ => break, |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | fn find_and_consume_colonrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]find_and_consume_colon().(&mut self) -> bool { |
| 518 | // Skip whitespace before colon |
| 519 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 520 | |
| 521 | // Check if we're at a colon or double-colon |
| 522 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#) |
| 523 | && matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(), ":" | "::") |
| 524 | { |
| 525 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 526 | return true; |
| 527 | } |
| 528 | |
| 529 | // Look ahead for a colon on the same line |
| 530 | let has_colon = self |
| 531 | .tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens. |
| 532 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 533 | .revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() |
| 534 | .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|(kind, _)| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().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().NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) |
| 535 | .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|(kind, text)| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().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# && (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().":" || 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()."::")); |
| 536 | |
| 537 | if has_colon { |
| 538 | // Consume tokens until we find the colon (staying on same line) |
| 539 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 540 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#) |
| 541 | && matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!( |
| 542 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(_, text)| text.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()), |
| 543 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(":" | "::") |
| 544 | ) |
| 545 | { |
| 546 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 547 | return true; |
| 548 | } |
| 549 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected ':'".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 554 | false |
| 555 | } |
| 556 | |
| 557 | fn parse_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule().(&mut self) { |
| 558 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 559 | |
| 560 | // Parse targets in a TARGETS node |
| 561 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 562 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(TARGETSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TARGETS#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 563 | let has_target = self.parse_rule_targetsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_targets().(); |
| 564 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 565 | |
| 566 | // Find and consume the colon |
| 567 | let has_colon = if has_target { |
| 568 | self.find_and_consume_colonrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]find_and_consume_colon().() |
| 569 | } else { |
| 570 | false |
| 571 | }; |
| 572 | |
| 573 | // Parse dependencies if we found both target and colon |
| 574 | if has_target && has_colon { |
| 575 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 576 | |
| 577 | // Detect a target-specific variable assignment: |
| 578 | // target: VAR [op] value |
| 579 | // by peeking IDENTIFIER (WS)? OPERATOR. If matched, treat |
| 580 | // the line as a scoped assignment (no prerequisites, no |
| 581 | // recipe) and produce a child VARIABLE node so callers can |
| 582 | // use the existing VariableDefinition accessors. |
| 583 | if self.looks_like_target_specific_assignmentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]looks_like_target_specific_assignment().() { |
| 584 | self.parse_target_specific_assignmentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_target_specific_assignment().(); |
| 585 | } else { |
| 586 | self.parse_rule_dependenciesrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_dependencies().(); |
| 587 | self.expect_eolrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]expect_eol().(); |
| 588 | |
| 589 | // Parse recipe lines |
| 590 | self.parse_rule_recipesrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_recipes().(); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 595 | } |
| 596 | |
| 597 | /// Look ahead (without consuming) for the `IDENTIFIER (WS)? OPERATOR` |
| 598 | /// pattern that marks a target-specific variable assignment such as |
| 599 | /// `all: CFLAGS = -O2`. |
| 600 | fn looks_like_target_specific_assignmentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]looks_like_target_specific_assignment().(&self) -> bool { |
| 601 | // tokens is reversed (last = current). We look from the end. |
| 602 | let n = self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 603 | if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().2 { |
| 604 | return false; |
| 605 | } |
| 606 | // Current token must be an IDENTIFIER (the variable name). |
| 607 | if self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..0 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().IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# { |
| 608 | return false; |
| 609 | } |
| 610 | let mut i = n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().2; |
| 611 | // Optional whitespace. |
| 612 | if self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..0 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().WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# { |
| 613 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 614 | return false; |
| 615 | } |
| 616 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 617 | } |
| 618 | // Next token must be an assignment OPERATOR. |
| 619 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..0 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# |
| 620 | && matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!( |
| 621 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..1.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(), |
| 622 | "=" | ":=" | "::=" | ":::=" | "+=" | "?=" | "!=" |
| 623 | ) |
| 624 | } |
| 625 | |
| 626 | /// Parse `VAR [op] value` after the rule's `:` colon, wrapped in a |
| 627 | /// child `VARIABLE` node. Consumes through the end-of-line. |
| 628 | fn parse_target_specific_assignmentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_target_specific_assignment().(&mut self) { |
| 629 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 630 | // Variable name (IDENTIFIER). |
| 631 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 632 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 633 | // Assignment operator. |
| 634 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#) { |
| 635 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 636 | } |
| 637 | // Optional whitespace before the value. |
| 638 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 639 | // Value lives in an EXPR node, like normal assignments. |
| 640 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 641 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 642 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 643 | } |
| 644 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // EXPR |
| 645 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 646 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 647 | } |
| 648 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // VARIABLE |
| 649 | } |
| 650 | |
| 651 | fn parse_rule_targetsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_targets().(&mut self) -> bool { |
| 652 | // Parse first target |
| 653 | let has_first_target = self.parse_rule_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_target().(); |
| 654 | |
| 655 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_first_target { |
| 656 | return false; |
| 657 | } |
| 658 | |
| 659 | // Parse additional targets until we hit the colon |
| 660 | loop { |
| 661 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 662 | |
| 663 | // Check if we're at a colon |
| 664 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#) && self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1 rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().":" { |
| 665 | break; |
| 666 | } |
| 667 | |
| 668 | // The target list may continue on the next physical line. |
| 669 | if self.consume_line_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]consume_line_continuation().() { |
| 670 | continue; |
| 671 | } |
| 672 | |
| 673 | // Try to parse another target |
| 674 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 675 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => { |
| 676 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.parse_rule_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule_target().() { |
| 677 | break; |
| 678 | } |
| 679 | } |
| 680 | _ => break, |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | true |
| 685 | } |
| 686 | |
| 687 | /// Returns true if the current token is an unescaped BACKSLASH |
| 688 | /// immediately followed by a NEWLINE (a line continuation). A backslash |
| 689 | /// preceded by an odd run of backslashes is itself escaped (`\\`) and |
| 690 | /// does not continue the line. |
| 691 | fn is_line_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_line_continuation().(&self) -> bool { |
| 692 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.pending_backslash_escaperust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#pending_backslash_escape. |
| 693 | && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(BACKSLASHrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BACKSLASH#) |
| 694 | && self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().2 |
| 695 | && self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..0 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().NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# |
| 696 | } |
| 697 | |
| 698 | /// Consume a backslash-newline line continuation and any indentation on |
| 699 | /// the continued line, so the caller keeps reading the logical line. |
| 700 | /// Returns false if the current position is not a line continuation. |
| 701 | fn consume_line_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]consume_line_continuation().(&mut self) -> bool { |
| 702 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_line_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_line_continuation().() { |
| 703 | return false; |
| 704 | } |
| 705 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // backslash |
| 706 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // newline |
| 707 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) { |
| 708 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 709 | } |
| 710 | true |
| 711 | } |
| 712 | |
| 713 | fn parse_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_comment().(&mut self) { |
| 714 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) { |
| 715 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume the comment token |
| 716 | |
| 717 | // Handle end of line or file after comment |
| 718 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 719 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume the newline |
| 720 | } else if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) { |
| 721 | // For whitespace after a comment, just consume it |
| 722 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 723 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 724 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 725 | } |
| 726 | } |
| 727 | // If we're at EOF after a comment, that's fine |
| 728 | } else { |
| 729 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected comment".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | fn parse_assignmentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_assignment().(&mut self) { |
| 734 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 735 | |
| 736 | // Handle `override` and `export` prefixes (in either order). Both |
| 737 | // are independent modifiers on a variable assignment. |
| 738 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 739 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2 { |
| 740 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) |
| 741 | && matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!( |
| 742 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(), |
| 743 | "export" | "override" |
| 744 | ) |
| 745 | { |
| 746 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 747 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 748 | } else { |
| 749 | break; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | // Parse variable name |
| 754 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 755 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) => self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(), |
| 756 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(), |
| 757 | _ => { |
| 758 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected variable name".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 759 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 760 | return; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | // Skip whitespace and parse operator |
| 765 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 766 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 767 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#) => { |
| 768 | let op = &self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1; |
| 769 | if ["=", ":=", "::=", ":::=", "+=", "?=", "!="].containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&op.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()) { |
| 770 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 771 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 772 | |
| 773 | // Parse value, creating nested EXPR nodes for |
| 774 | // variable references. A trailing `# comment` is |
| 775 | // left as a sibling COMMENT token, not bundled |
| 776 | // into the EXPR. |
| 777 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 778 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 779 | && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) |
| 780 | && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) |
| 781 | { |
| 782 | // The value may continue on the next physical line. |
| 783 | if self.consume_line_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]consume_line_continuation().() { |
| 784 | continue; |
| 785 | } |
| 786 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) { |
| 787 | self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(); |
| 788 | } else { |
| 789 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 790 | } |
| 791 | } |
| 792 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 793 | |
| 794 | // Optional trailing comment. |
| 795 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) { |
| 796 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 797 | } |
| 798 | |
| 799 | // Expect newline |
| 800 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 801 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 802 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() { |
| 803 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected newline after variable value".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 804 | } |
| 805 | } else { |
| 806 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("invalid assignment operator: {}", op)); |
| 807 | } |
| 808 | } |
| 809 | // Bare "export VARNAME" without assignment operator is valid GNU Make |
| 810 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) => { |
| 811 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 812 | } |
| 813 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 814 | // EOF after export VARNAME is fine |
| 815 | } |
| 816 | _ => self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected assignment operator".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 817 | } |
| 818 | |
| 819 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 820 | } |
| 821 | |
| 822 | fn parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(&mut self) { |
| 823 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 824 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume $ |
| 825 | |
| 826 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN#) || self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LBRACE#) { |
| 827 | let is_brace = self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LBRACE#); |
| 828 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume ( or { |
| 829 | |
| 830 | if is_brace { |
| 831 | // For ${...}, consume until matching } |
| 832 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RBRACE#) { |
| 833 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) { |
| 834 | self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(); |
| 835 | } else { |
| 836 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 837 | } |
| 838 | } |
| 839 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RBRACE#) { |
| 840 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume } |
| 841 | } |
| 842 | } else { |
| 843 | // Start by checking if this is a function like $(shell ...) |
| 844 | let mut is_function = false; |
| 845 | |
| 846 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) { |
| 847 | let function_name = &self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1; |
| 848 | // Common makefile functions |
| 849 | let known_functions = [ |
| 850 | "shell", "wildcard", "call", "eval", "file", "abspath", "dir", |
| 851 | ]; |
| 852 | if known_functions.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&function_name.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()) { |
| 853 | is_function = true; |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | if is_function { |
| 858 | // Preserve the function name |
| 859 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 860 | |
| 861 | // Parse the rest of the function call, handling nested variable references |
| 862 | self.consume_balanced_parensrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]consume_balanced_parens().(1); |
| 863 | } else { |
| 864 | // Handle regular variable references |
| 865 | self.parse_parenthesized_expr_internalrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_parenthesized_expr_internal().(true); |
| 866 | } |
| 867 | } |
| 868 | } else if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 869 | // Single character variable like $X or $$ |
| 870 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 871 | } else { |
| 872 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected variable name after $".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 873 | } |
| 874 | |
| 875 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 876 | } |
| 877 | |
| 878 | // Helper method to parse a conditional comparison (ifeq/ifneq) |
| 879 | // Supports both syntaxes: (arg1,arg2) and "arg1" "arg2" |
| 880 | fn parse_parenthesized_exprrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_parenthesized_expr().(&mut self) { |
| 881 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 882 | |
| 883 | // Check if we have parenthesized or quoted syntax |
| 884 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN#) { |
| 885 | // Parenthesized syntax: ifeq (arg1,arg2) |
| 886 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume opening paren |
| 887 | self.parse_parenthesized_expr_internalrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_parenthesized_expr_internal().(false); |
| 888 | } else if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(QUOTErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#QUOTE#) { |
| 889 | // Quoted syntax: ifeq "arg1" "arg2" or ifeq 'arg1' 'arg2' |
| 890 | self.parse_quoted_comparisonrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_quoted_comparison().(); |
| 891 | } else { |
| 892 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected opening parenthesis or quote".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 893 | } |
| 894 | |
| 895 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 896 | } |
| 897 | |
| 898 | // Internal helper to parse parenthesized expressions |
| 899 | fn parse_parenthesized_expr_internalrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_parenthesized_expr_internal().(&mut self, is_variable_ref: bool) { |
| 900 | let mut paren_count = 1; |
| 901 | // Each nested LPAREN opens an EXPR node that the matching RPAREN |
| 902 | // closes. If EOF arrives before those RPARENs do, we must still |
| 903 | // close them or the green tree ends up unbalanced (rowan panics |
| 904 | // in GreenNodeBuilder::finish). |
| 905 | let mut open_nested = 0u32; |
| 906 | |
| 907 | while paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 908 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 909 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN#) => { |
| 910 | paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 911 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 912 | // Start a new expression node for nested parentheses |
| 913 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 914 | open_nested rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1; |
| 915 | } |
| 916 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN#) => { |
| 917 | paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1; |
| 918 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 919 | if paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 { |
| 920 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 921 | open_nested rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign().1; |
| 922 | } |
| 923 | } |
| 924 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(QUOTErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#QUOTE#) => { |
| 925 | // Handle quoted strings |
| 926 | self.parse_quoted_stringrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_quoted_string().(); |
| 927 | } |
| 928 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => { |
| 929 | // Handle variable references |
| 930 | self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(); |
| 931 | } |
| 932 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(), |
| 933 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 934 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().(if is_variable_ref { |
| 935 | "unclosed variable reference".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 936 | } else { |
| 937 | "unclosed parenthesis".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 938 | }); |
| 939 | break; |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#open_nested { |
| 945 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 946 | } |
| 947 | |
| 948 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_variable_ref { |
| 949 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 950 | self.expect_eolrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]expect_eol().(); |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | // Helper method to parse quoted comparison for ifeq/ifneq |
| 955 | // Handles: "arg1" "arg2" or 'arg1' 'arg2' |
| 956 | fn parse_quoted_comparisonrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_quoted_comparison().(&mut self) { |
| 957 | // First quoted string - lexer already tokenized the entire string |
| 958 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(QUOTErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#QUOTE#) { |
| 959 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume the entire first quoted string token |
| 960 | } else { |
| 961 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected first quoted argument".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 962 | } |
| 963 | |
| 964 | // Skip whitespace between the two arguments |
| 965 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 966 | |
| 967 | // Second quoted string - lexer already tokenized the entire string |
| 968 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(QUOTErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#QUOTE#) { |
| 969 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume the entire second quoted string token |
| 970 | } else { |
| 971 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected second quoted argument".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 972 | } |
| 973 | |
| 974 | // Skip trailing whitespace and expect end of line |
| 975 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 976 | self.expect_eolrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]expect_eol().(); |
| 977 | } |
| 978 | |
| 979 | // Handle parsing a quoted string. The lexer emits the entire quoted |
| 980 | // string (including both delimiters) as a single QUOTE token, so we |
| 981 | // just consume that one token. |
| 982 | fn parse_quoted_stringrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_quoted_string().(&mut self) { |
| 983 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(QUOTErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#QUOTE#) { |
| 984 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | fn parse_conditional_keywordrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_conditional_keyword().(&mut 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#> { |
| 989 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) { |
| 990 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().( |
| 991 | "expected conditional keyword (ifdef, ifndef, ifeq, or ifneq)".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 992 | ); |
| 993 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 994 | } |
| 995 | |
| 996 | let token = self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(); |
| 997 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]::is_conditional_startrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_conditional_start().(&token) { |
| 998 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unknown conditional directive: {}", token)); |
| 999 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 1000 | } |
| 1001 | |
| 1002 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1003 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) |
| 1004 | } |
| 1005 | |
| 1006 | fn parse_simple_conditionrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_simple_condition().(&mut self) { |
| 1007 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 1008 | |
| 1009 | // Skip any leading whitespace |
| 1010 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1011 | |
| 1012 | // Collect variable names |
| 1013 | let mut found_var = false; |
| 1014 | |
| 1015 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1016 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 1017 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) => self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(), |
| 1018 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => { |
| 1019 | found_var = true; |
| 1020 | self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(); |
| 1021 | } |
| 1022 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => { |
| 1023 | // Accept any token as part of condition |
| 1024 | found_var = true; |
| 1025 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1026 | } |
| 1027 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => break, |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().found_var { |
| 1032 | // Empty condition is an error in GNU Make |
| 1033 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected condition after conditional directive".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1034 | } |
| 1035 | |
| 1036 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1037 | |
| 1038 | // Expect end of line |
| 1039 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1040 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1041 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() { |
| 1042 | self.skip_until_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_until_newline().(); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | // Helper to check if a token starts a conditional block. |
| 1047 | // Note this requires an exact match: a variable named e.g. `ifpkg` |
| 1048 | // merely starts with "if" and is not a conditional directive. |
| 1049 | fn is_conditional_startrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_conditional_start().(token: &str) -> bool { |
| 1050 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(token, "ifdef" | "ifndef" | "ifeq" | "ifneq") |
| 1051 | } |
| 1052 | |
| 1053 | // Helper to check if a token is a conditional directive |
| 1054 | fn is_conditional_directiverust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_conditional_directive().(&self, token: &str) -> bool { |
| 1055 | Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]::is_conditional_startrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_conditional_start().(token) || token 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()."else" || token 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()."endif" |
| 1056 | } |
| 1057 | |
| 1058 | // Helper method to handle conditional token |
| 1059 | fn handle_conditional_tokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]handle_conditional_token().(&mut self, token: &str, depth: &mut usize) -> bool { |
| 1060 | match token { |
| 1061 | "ifdef" | "ifndef" | "ifeq" | "ifneq" |
| 1062 | if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.variantrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#variant., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileVariantrust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#::GNUMakerust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#GNUMake#)) => |
| 1063 | { |
| 1064 | // Don't increment depth here - parse_conditional manages its own depth internally |
| 1065 | // Incrementing here causes the outer conditional to never exit its loop |
| 1066 | self.parse_conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_conditional().(); |
| 1067 | true |
| 1068 | } |
| 1069 | "else" => { |
| 1070 | // Not valid outside of a conditional |
| 1071 | if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 1072 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("else without matching if".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1073 | // Always consume a token to guarantee progress |
| 1074 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1075 | false |
| 1076 | } else { |
| 1077 | // Start CONDITIONAL_ELSE node |
| 1078 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_ELSErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ELSE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 1079 | |
| 1080 | // Consume the 'else' token |
| 1081 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1082 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1083 | |
| 1084 | // Check if this is "else <conditional>" (else ifdef, else ifeq, etc.) |
| 1085 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) { |
| 1086 | let next_token = &self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1; |
| 1087 | if Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]::is_conditional_startrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_conditional_start().(next_token) { |
| 1088 | // This is "else ifdef", "else ifeq", etc. |
| 1089 | // Parse the conditional part |
| 1090 | match next_token.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() { |
| 1091 | "ifdef" | "ifndef" => { |
| 1092 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume the directive token |
| 1093 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1094 | self.parse_simple_conditionrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_simple_condition().(); |
| 1095 | } |
| 1096 | "ifeq" | "ifneq" => { |
| 1097 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); // Consume the directive token |
| 1098 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1099 | self.parse_parenthesized_exprrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_parenthesized_expr().(); |
| 1100 | } |
| 1101 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 1102 | } |
| 1103 | // The newline will be consumed by the conditional body loop |
| 1104 | } else { |
| 1105 | // Plain 'else' with something else after it (not a conditional keyword) |
| 1106 | // The newline will be consumed by the conditional body loop |
| 1107 | } |
| 1108 | } else { |
| 1109 | // Plain 'else' - the newline will be consumed by the conditional body loop |
| 1110 | } |
| 1111 | |
| 1112 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // finish CONDITIONAL_ELSE |
| 1113 | true |
| 1114 | } |
| 1115 | } |
| 1116 | "endif" => { |
| 1117 | // Not valid outside of a conditional |
| 1118 | if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 1119 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("endif without matching if".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1120 | // Always consume a token to guarantee progress |
| 1121 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1122 | false |
| 1123 | } else { |
| 1124 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 1125 | |
| 1126 | // Start CONDITIONAL_ENDIF node |
| 1127 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_ENDIFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ENDIF#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 1128 | |
| 1129 | // Consume the endif |
| 1130 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1131 | |
| 1132 | // Be more permissive with what follows endif |
| 1133 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1134 | |
| 1135 | // Handle common patterns after endif: |
| 1136 | // 1. Comments: endif # comment |
| 1137 | // 2. Whitespace at end of file |
| 1138 | // 3. Newlines |
| 1139 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) { |
| 1140 | self.parse_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_comment().(); |
| 1141 | } else if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1142 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1143 | } else if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) { |
| 1144 | // Skip whitespace without an error |
| 1145 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1146 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1147 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1148 | } |
| 1149 | // If we're at EOF after whitespace, that's fine too |
| 1150 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() { |
| 1151 | // For any other tokens, be lenient and just consume until EOL |
| 1152 | // This makes the parser more resilient to various "endif" formattings |
| 1153 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1154 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1155 | } |
| 1156 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1157 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1158 | } |
| 1159 | } |
| 1160 | // If we're at EOF after endif, that's fine |
| 1161 | |
| 1162 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // finish CONDITIONAL_ENDIF |
| 1163 | true |
| 1164 | } |
| 1165 | } |
| 1166 | _ => false, |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | fn parse_conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_conditional().(&mut self) { |
| 1171 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 1172 | |
| 1173 | // Start the initial conditional (ifdef/ifndef/ifeq/ifneq) |
| 1174 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_IFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_IF#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 1175 | |
| 1176 | // Parse the conditional keyword |
| 1177 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = self.parse_conditional_keywordrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_conditional_keyword().() else { |
| 1178 | self.skip_until_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_until_newline().(); |
| 1179 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // finish CONDITIONAL_IF |
| 1180 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // finish CONDITIONAL |
| 1181 | return; |
| 1182 | }; |
| 1183 | |
| 1184 | // Skip whitespace after keyword |
| 1185 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1186 | |
| 1187 | // Parse the condition based on keyword type |
| 1188 | match token.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() { |
| 1189 | "ifdef" | "ifndef" => { |
| 1190 | self.parse_simple_conditionrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_simple_condition().(); |
| 1191 | } |
| 1192 | "ifeq" | "ifneq" => { |
| 1193 | self.parse_parenthesized_exprrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_parenthesized_expr().(); |
| 1194 | } |
| 1195 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("Invalid conditional token"), |
| 1196 | } |
| 1197 | |
| 1198 | // Skip any trailing whitespace and check for inline comments |
| 1199 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1200 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) { |
| 1201 | self.parse_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_comment().(); |
| 1202 | } |
| 1203 | // Note: expect_eol is already called by parse_simple_condition() and parse_parenthesized_expr() |
| 1204 | |
| 1205 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // finish CONDITIONAL_IF |
| 1206 | |
| 1207 | // Parse the conditional body |
| 1208 | let mut depth = 1; |
| 1209 | |
| 1210 | // More reliable loop detection |
| 1211 | let mut position_count = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::<usize, usize>::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(); |
| 1212 | let max_repetitions = 15; // Permissive but safe limit |
| 1213 | |
| 1214 | while depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() { |
| 1215 | // Track position to detect infinite loops |
| 1216 | let current_pos = self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 1217 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().position_count.entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(current_pos).or_insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert().(0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 1218 | |
| 1219 | // If we've seen the same position too many times, break |
| 1220 | // This prevents infinite loops while allowing complex parsing |
| 1221 | if position_count.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(¤t_pos).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().&max_repetitions { |
| 1222 | // Instead of adding an error, just break out silently |
| 1223 | // to avoid breaking tests that expect no errors |
| 1224 | break; |
| 1225 | } |
| 1226 | |
| 1227 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 1228 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 1229 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("unterminated conditional (missing endif)".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1230 | break; |
| 1231 | } |
| 1232 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) => { |
| 1233 | let token = self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(); |
| 1234 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.handle_conditional_tokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]handle_conditional_token().(&token, &mut depth) { |
| 1235 | if token rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."include" || token rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."-include" || token rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."sinclude" { |
| 1236 | self.parse_includerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_include().(); |
| 1237 | } else { |
| 1238 | self.parse_normal_contentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_normal_content().(); |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) => self.parse_recipe_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_recipe_line().(), |
| 1243 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) => self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(), |
| 1244 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) => self.parse_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_comment().(), |
| 1245 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) => self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(), |
| 1246 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => self.parse_normal_contentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_normal_content().(), |
| 1247 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(QUOTErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#QUOTE#) => self.parse_quoted_stringrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_quoted_string().(), |
| 1248 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => { |
| 1249 | // Be more tolerant of unexpected tokens in conditionals |
| 1250 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1256 | } |
| 1257 | |
| 1258 | // Helper to parse normal content (either assignment or rule) |
| 1259 | fn parse_normal_contentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_normal_content().(&mut self) { |
| 1260 | // Skip any leading whitespace |
| 1261 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1262 | |
| 1263 | // Check if this could be a variable assignment |
| 1264 | if self.is_assignment_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_assignment_line().() { |
| 1265 | self.parse_assignmentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_assignment().(); |
| 1266 | } else { |
| 1267 | // Try to handle as a rule |
| 1268 | self.parse_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule().(); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | fn parse_includerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_include().(&mut self) { |
| 1273 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 1274 | |
| 1275 | // Consume include keyword variant |
| 1276 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) |
| 1277 | || (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().["include", "-include", "sinclude"] |
| 1278 | .containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().())) |
| 1279 | { |
| 1280 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected include directive".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1281 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1282 | return; |
| 1283 | } |
| 1284 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1285 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1286 | |
| 1287 | // Parse file paths |
| 1288 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 1289 | let mut found_path = false; |
| 1290 | |
| 1291 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1292 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 1293 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) => self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(), |
| 1294 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => { |
| 1295 | found_path = true; |
| 1296 | self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(); |
| 1297 | } |
| 1298 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => { |
| 1299 | // Accept any token as part of the path |
| 1300 | found_path = true; |
| 1301 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1302 | } |
| 1303 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => break, |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().found_path { |
| 1308 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected file path after include".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1309 | } |
| 1310 | |
| 1311 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1312 | |
| 1313 | // Expect newline |
| 1314 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1315 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1316 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() { |
| 1317 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("expected newline after include".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1318 | self.skip_until_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_until_newline().(); |
| 1319 | } |
| 1320 | |
| 1321 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1322 | } |
| 1323 | |
| 1324 | /// Parse a `vpath` directive in one of its three forms: |
| 1325 | /// |
| 1326 | /// - `vpath PATTERN DIRS` - add a search path for files matching PATTERN |
| 1327 | /// - `vpath PATTERN` - clear the search path for PATTERN |
| 1328 | /// - `vpath` - clear every `vpath` setting |
| 1329 | /// |
| 1330 | /// Produces a `VPATH` node containing the keyword token, optional |
| 1331 | /// pattern (as an IDENTIFIER) and an optional EXPR holding the |
| 1332 | /// directory list. |
| 1333 | fn parse_vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_vpath().(&mut self) { |
| 1334 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(VPATHrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VPATH#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 1335 | // Consume the `vpath` keyword. |
| 1336 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1337 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1338 | |
| 1339 | // Optional pattern (rest of header until whitespace). |
| 1340 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1341 | // The pattern token sequence (until whitespace or newline). |
| 1342 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(kind) = self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 1343 | match kind { |
| 1344 | WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# | NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# => break, |
| 1345 | _ => self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(), |
| 1346 | } |
| 1347 | } |
| 1348 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1349 | |
| 1350 | // Optional directory list (everything else on the line). |
| 1351 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1352 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 1353 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1354 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1355 | } |
| 1356 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | // Consume the trailing newline. |
| 1361 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1362 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1363 | } |
| 1364 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1365 | } |
| 1366 | |
| 1367 | /// Parse a `define`/`endef` multi-line variable definition. |
| 1368 | /// |
| 1369 | /// Produces a `VARIABLE` node structured like a regular assignment: |
| 1370 | /// |
| 1371 | /// - the `define` keyword itself (kept as an `IDENTIFIER` token); |
| 1372 | /// - the variable's identifier; |
| 1373 | /// - the assignment operator (defaults to `=` if absent); |
| 1374 | /// - an `EXPR` node containing the verbatim body (without the |
| 1375 | /// surrounding newlines that bracket it); |
| 1376 | /// - the closing `endef` token. |
| 1377 | /// |
| 1378 | /// Because the body is wrapped in an `EXPR` node, the existing |
| 1379 | /// `VariableDefinition::name()` / `assignment_operator()` / |
| 1380 | /// `raw_value()` accessors work transparently for `define` blocks. |
| 1381 | fn parse_definerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_define().(&mut self) { |
| 1382 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 1383 | |
| 1384 | // Consume the `define` keyword itself. |
| 1385 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1386 | // Optional whitespace then the variable name (an IDENTIFIER). |
| 1387 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1388 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) { |
| 1389 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1390 | } |
| 1391 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1392 | // Optional assignment operator (e.g. `:=`, `+=`, `?=`). |
| 1393 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#) { |
| 1394 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1395 | } |
| 1396 | // Skip any trailing whitespace on the header line. |
| 1397 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1398 | // Consume the header-terminating newline (kept as a child). |
| 1399 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1400 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1401 | } |
| 1402 | |
| 1403 | // The body of the define lives in an EXPR node so that |
| 1404 | // `raw_value()` returns it. We consume token-by-token until we |
| 1405 | // see an `endef` line at depth 0, tracking nested `define`. |
| 1406 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#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().()); |
| 1407 | let mut depth: usize = 1; |
| 1408 | 'body: while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() { |
| 1409 | match self.first_token_on_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]first_token_on_line().() { |
| 1410 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("endef") => { |
| 1411 | depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 1412 | if depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 1413 | break 'body; |
| 1414 | } |
| 1415 | } |
| 1416 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("define") => depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1, |
| 1417 | _ => {} |
| 1418 | } |
| 1419 | // Consume one line into the EXPR body. |
| 1420 | self.skip_until_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_until_newline().(); |
| 1421 | } |
| 1422 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); // EXPR |
| 1423 | |
| 1424 | // Consume the closing `endef` line itself (if we found it). |
| 1425 | if depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 1426 | self.skip_until_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_until_newline().(); |
| 1427 | } else { |
| 1428 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("missing `endef` for `define`".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1429 | } |
| 1430 | |
| 1431 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1432 | } |
| 1433 | |
| 1434 | /// Return the text of the first non-whitespace token on the current |
| 1435 | /// line, if it is an identifier. Used to detect `define`/`endef`. |
| 1436 | fn first_token_on_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]first_token_on_line().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> { |
| 1437 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens. |
| 1438 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 1439 | .revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() |
| 1440 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/rev/impl#[`Rev<I>`][Iterator]find().(|(kind, _)| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().kind, WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# | INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#)) |
| 1441 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]filter().(|(kind, _)| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().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#) |
| 1442 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(_, text)| text.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()) |
| 1443 | } |
| 1444 | |
| 1445 | fn parse_identifier_tokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_identifier_token().(&mut self) -> bool { |
| 1446 | let token = &self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1; |
| 1447 | |
| 1448 | // Handle special cases first |
| 1449 | if token.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("%") { |
| 1450 | self.parse_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_rule().(); |
| 1451 | return true; |
| 1452 | } |
| 1453 | |
| 1454 | if Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]::is_conditional_startrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_conditional_start().(token) |
| 1455 | && matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.variantrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#variant., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileVariantrust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#::GNUMakerust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#GNUMake#)) |
| 1456 | { |
| 1457 | self.parse_conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_conditional().(); |
| 1458 | return true; |
| 1459 | } |
| 1460 | |
| 1461 | if token 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" || token 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" || token 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" { |
| 1462 | self.parse_includerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_include().(); |
| 1463 | return true; |
| 1464 | } |
| 1465 | |
| 1466 | if token 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" { |
| 1467 | self.parse_definerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_define().(); |
| 1468 | return true; |
| 1469 | } |
| 1470 | |
| 1471 | if token 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()."vpath" { |
| 1472 | self.parse_vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_vpath().(); |
| 1473 | return true; |
| 1474 | } |
| 1475 | |
| 1476 | // Handle normal content (assignment or rule) |
| 1477 | self.parse_normal_contentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_normal_content().(); |
| 1478 | true |
| 1479 | } |
| 1480 | |
| 1481 | fn parse_tokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_token().(&mut self) -> bool { |
| 1482 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 1483 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => false, |
| 1484 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#) => { |
| 1485 | let token = &self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1; |
| 1486 | if self.is_conditional_directiverust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_conditional_directive().(token) |
| 1487 | && matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.variantrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#variant., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileVariantrust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#::GNUMakerust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#GNUMake#)) |
| 1488 | { |
| 1489 | self.parse_conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_conditional().(); |
| 1490 | true |
| 1491 | } else { |
| 1492 | self.parse_identifier_tokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_identifier_token().() |
| 1493 | } |
| 1494 | } |
| 1495 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => { |
| 1496 | self.parse_normal_contentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_normal_content().(); |
| 1497 | true |
| 1498 | } |
| 1499 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) => { |
| 1500 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 1501 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1502 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1503 | true |
| 1504 | } |
| 1505 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) => { |
| 1506 | self.parse_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_comment().(); |
| 1507 | true |
| 1508 | } |
| 1509 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) => { |
| 1510 | // Special case for trailing whitespace |
| 1511 | if self.is_end_of_file_or_newline_after_whitespacerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_end_of_file_or_newline_after_whitespace().() { |
| 1512 | // If the whitespace is just before EOF or a newline, consume it all without errors |
| 1513 | // to be more lenient with final whitespace |
| 1514 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1515 | return true; |
| 1516 | } |
| 1517 | |
| 1518 | // Special case for indented lines that might be part of help text or documentation |
| 1519 | // Look ahead to see what comes after the whitespace |
| 1520 | let look_ahead_pos = self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().().saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); |
| 1521 | let mut is_documentation_or_help = false; |
| 1522 | |
| 1523 | if look_ahead_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 1524 | let next_token = &self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().look_ahead_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 1525 | // Consider this documentation if it's an identifier starting with @, a comment, |
| 1526 | // or any reasonable text |
| 1527 | if next_token.0 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# |
| 1528 | || next_token.0 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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# |
| 1529 | || next_token.0 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().TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT# |
| 1530 | { |
| 1531 | is_documentation_or_help = true; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | if is_documentation_or_help { |
| 1536 | // For documentation/help text lines, just consume all tokens until newline |
| 1537 | // without generating errors |
| 1538 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1539 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1540 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1541 | } |
| 1542 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1543 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1544 | } |
| 1545 | } else { |
| 1546 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1547 | } |
| 1548 | true |
| 1549 | } |
| 1550 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) => { |
| 1551 | // We'll consume the INDENT token |
| 1552 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1553 | |
| 1554 | // Consume the rest of the line |
| 1555 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1556 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1557 | } |
| 1558 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1559 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1560 | } |
| 1561 | true |
| 1562 | } |
| 1563 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(kind) => { |
| 1564 | // `error()` already consumes the offending token; bumping |
| 1565 | // again here would pop past the end of the stack when |
| 1566 | // this is the last token. |
| 1567 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unexpected token {:?}", kind)); |
| 1568 | true |
| 1569 | } |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | fn parserust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse().(mut self) -> Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse# { |
| 1574 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(ROOTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ROOT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 1575 | |
| 1576 | while self.parse_tokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_token().() {} |
| 1577 | |
| 1578 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 1579 | |
| 1580 | Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse# { |
| 1581 | green_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#green_node.: self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().(), |
| 1582 | errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.: self.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#errors., |
| 1583 | positioned_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#positioned_errors.: self.positioned_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#positioned_errors., |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | // Simplify the is_assignment_line method by making it more direct |
| 1588 | fn is_assignment_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_assignment_line().(&mut self) -> bool { |
| 1589 | let assignment_ops = ["=", ":=", "::=", ":::=", "+=", "?=", "!="]; |
| 1590 | let mut pos = self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().().saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); |
| 1591 | let mut seen_identifier = false; |
| 1592 | let mut seen_directive = false; // export or override prefix |
| 1593 | |
| 1594 | while pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 1595 | let (kind, text) = &self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().pos]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 1596 | |
| 1597 | match kind { |
| 1598 | NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# => break, |
| 1599 | IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# if 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" || 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" => seen_directive = true, |
| 1600 | IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().seen_identifier => seen_identifier = true, |
| 1601 | OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# if assignment_ops.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&text.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()) => { |
| 1602 | return seen_identifier || seen_directive |
| 1603 | } |
| 1604 | OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# if 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().":" || 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()."::" => return false, // It's a rule if we see a colon first |
| 1605 | WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# => (), |
| 1606 | _ if seen_directive => return true, // Everything after export/override is part of the assignment |
| 1607 | _ => return false, |
| 1608 | } |
| 1609 | pos = pos.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); |
| 1610 | } |
| 1611 | // Bare "export VARNAME" (without assignment operator) is a valid GNU Make directive |
| 1612 | seen_directive |
| 1613 | } |
| 1614 | |
| 1615 | /// Advance one token, adding it to the current branch of the tree builder. |
| 1616 | fn bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(&mut self) { |
| 1617 | let (kind, text) = self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1618 | // Track backslash-run parity: each backslash flips the flag, any |
| 1619 | // other token clears it. See `pending_backslash_escape`. |
| 1620 | self.pending_backslash_escaperust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#pending_backslash_escape. = 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().BACKSLASHrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BACKSLASH# && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.pending_backslash_escaperust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#pending_backslash_escape.; |
| 1621 | self.builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder..tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(kind.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), text.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()); |
| 1622 | if self.current_token_indexrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#current_token_index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 1623 | self.current_token_indexrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#current_token_index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 1624 | } |
| 1625 | } |
| 1626 | /// Peek at the first unprocessed token |
| 1627 | fn currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#> { |
| 1628 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(kind, _)| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().kind) |
| 1629 | } |
| 1630 | |
| 1631 | fn expect_eolrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]expect_eol().(&mut self) { |
| 1632 | // Skip any whitespace before looking for a newline |
| 1633 | self.skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(); |
| 1634 | |
| 1635 | // GNU Make allows a comment at the end of a directive line. |
| 1636 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#) { |
| 1637 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1638 | } |
| 1639 | |
| 1640 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 1641 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) => { |
| 1642 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1643 | } |
| 1644 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 1645 | // End of file is also acceptable |
| 1646 | } |
| 1647 | n => { |
| 1648 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("expected newline, got {:?}", n)); |
| 1649 | // Try to recover by skipping to the next newline |
| 1650 | self.skip_until_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_until_newline().(); |
| 1651 | } |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | // Helper to check if we're at EOF |
| 1656 | fn is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().(&self) -> bool { |
| 1657 | self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() |
| 1658 | } |
| 1659 | |
| 1660 | // Helper to check if we're at EOF or there's only whitespace left |
| 1661 | fn is_at_eof_or_only_whitespacerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof_or_only_whitespace().(&self) -> bool { |
| 1662 | if self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() { |
| 1663 | return true; |
| 1664 | } |
| 1665 | |
| 1666 | // Check if only whitespace and newlines remain |
| 1667 | self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens. |
| 1668 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 1669 | .revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() |
| 1670 | .allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|(kind, _)| matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().kind, WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# | NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#)) |
| 1671 | } |
| 1672 | |
| 1673 | fn skip_wsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_ws().(&mut self) { |
| 1674 | while self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#) { |
| 1675 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().() |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | fn skip_until_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]skip_until_newline().(&mut self) { |
| 1680 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof().() && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() 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().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1681 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1682 | } |
| 1683 | if self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 1684 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | // Helper to handle nested parentheses and collect tokens until matching closing parenthesis |
| 1689 | fn consume_balanced_parensrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]consume_balanced_parens().(&mut self, start_paren_count: usize) -> usize { |
| 1690 | let mut paren_count = start_paren_count; |
| 1691 | |
| 1692 | while paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 1693 | match self.currentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]current().() { |
| 1694 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN#) => { |
| 1695 | paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 1696 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1697 | } |
| 1698 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN#) => { |
| 1699 | paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 1700 | self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(); |
| 1701 | if paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 1702 | break; |
| 1703 | } |
| 1704 | } |
| 1705 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#) => { |
| 1706 | // Handle nested variable references |
| 1707 | self.parse_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse_variable_reference().(); |
| 1708 | } |
| 1709 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => self.bumprust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]bump().(), |
| 1710 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 1711 | self.errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]error().("unclosed parenthesis".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1712 | break; |
| 1713 | } |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | paren_count |
| 1718 | } |
| 1719 | |
| 1720 | // Helper to check if we're near the end of the file with just whitespace |
| 1721 | fn is_end_of_file_or_newline_after_whitespacerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_end_of_file_or_newline_after_whitespace().(&self) -> bool { |
| 1722 | // Use our new helper method |
| 1723 | if self.is_at_eof_or_only_whitespacerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]is_at_eof_or_only_whitespace().() { |
| 1724 | return true; |
| 1725 | } |
| 1726 | |
| 1727 | // If there are 1 or 0 tokens left, we're at EOF |
| 1728 | if self.tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().1 { |
| 1729 | return true; |
| 1730 | } |
| 1731 | |
| 1732 | false |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | let mut tokens = lexrust-analyzer cargo makefile-lossless 0.3.40 lex/lex().(text); |
| 1737 | |
| 1738 | // Build token positions in forward order before reversing |
| 1739 | let mut token_positions = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(tokens.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 1740 | let mut position = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#::fromrust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`From<u32>`]from().(0); |
| 1741 | for (_kind, text) in &tokens { |
| 1742 | let start = position; |
| 1743 | let end = start rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Add<Self>`]add().+rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Add<Self>`]add(). rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Add<Self>`]add().rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#::ofrust-analyzer cargo text-size 1.1.1 size/impl#[TextSize]of().(text.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()); |
| 1744 | token_positions.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((start, end)); |
| 1745 | position = end; |
| 1746 | } |
| 1747 | |
| 1748 | let current_token_index = tokens.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().().saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); |
| 1749 | tokens.reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]reverse().(); |
| 1750 | Parserrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser# { |
| 1751 | tokensrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#tokens., |
| 1752 | builderrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#builder.: GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().(), |
| 1753 | errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#errors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 1754 | positioned_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#positioned_errors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 1755 | token_positionsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#token_positions., |
| 1756 | current_token_indexrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#current_token_index., |
| 1757 | original_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#original_text.: text.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 1758 | variantrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#variant., |
| 1759 | pending_backslash_escaperust-analyzer cargo makefile-lossless 0.3.40 lossless/Parser#pending_backslash_escape.: false, |
| 1760 | } |
| 1761 | .parserust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parser]parse().() |
| 1762 | } |
| 1763 | |
| 1764 | /// To work with the parse results we need a view into the |
| 1765 | /// green tree - the Syntax tree. |
| 1766 | /// It is also immutable, like a GreenNode, |
| 1767 | /// but it contains parent pointers, offsets, and |
| 1768 | /// has identity semantics. |
| 1769 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) type SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode# = rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxNoderust-analyzer cargo rowan 0.16.1 api/SyntaxNode#<Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#>; |
| 1770 | #[allow(unused)] |
| 1771 | type SyntaxTokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxToken# = rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxTokenrust-analyzer cargo rowan 0.16.1 api/SyntaxToken#<Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#>; |
| 1772 | #[allow(unused)] |
| 1773 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) type SyntaxElementrust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxElement# = rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#<SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#, SyntaxTokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxToken#>; |
| 1774 | |
| 1775 | impl Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse# { |
| 1776 | fn syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]syntax().(&self) -> SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode# { |
| 1777 | SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(self.green_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#green_node..clonerust-analyzer cargo rowan 0.16.1 green/node/impl#[GreenNode][Clone]clone().()) |
| 1778 | } |
| 1779 | |
| 1780 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) fn rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(&self) -> Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# { |
| 1781 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]cast().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]syntax().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | /// Calculate line and column (both 0-indexed) for the given offset in the tree. |
| 1786 | /// Column is measured in bytes from the start of the line. |
| 1787 | fn line_col_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/line_col_at_offset().(node: &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#, offset: rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#) -> (usize, usize) { |
| 1788 | let root = node.ancestorsrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]ancestors().().lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| node.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().()); |
| 1789 | let mut line = 0; |
| 1790 | let mut last_newline_offset = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#::fromrust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`From<u32>`]from().(0); |
| 1791 | |
| 1792 | for element in root.preorder_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]preorder_with_tokens().() { |
| 1793 | if let rowanrust-analyzer cargo rowan 0.16.1 crate/::WalkEventrust-analyzer cargo rowan 0.16.1 utility_types/WalkEvent#::Enterrust-analyzer cargo rowan 0.16.1 utility_types/WalkEvent#Enter#(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)) = element { |
| 1794 | if token.text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text_range().().startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge().offset { |
| 1795 | break; |
| 1796 | } |
| 1797 | |
| 1798 | // Count newlines and track position of last one |
| 1799 | for (idx, _) in token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().().match_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]match_indices().('\n') { |
| 1800 | line rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 1801 | last_newline_offset = |
| 1802 | token.text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text_range().().startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().() rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Add<Self>`]add().+rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Add<Self>`]add(). rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Add<Self>`]add().rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#::fromrust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`From<u32>`]from().((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) as u32); |
| 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | let column: usize = (offset rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Sub<Self>`]sub().-rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Sub<Self>`]sub(). rust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`Sub<Self>`]sub().last_newline_offset).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 1808 | (line, column) |
| 1809 | } |
| 1810 | |
| 1811 | macro_rules! ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node! { |
| 1812 | ($ast:ident, $kind:ident) => { |
| 1813 | #[derive(Clone, PartialEq, Eq, Hash)] |
| 1814 | #[repr(transparent)] |
| 1815 | /// An AST node for $ast |
| 1816 | pub struct $ast(SyntaxNode); |
| 1817 | |
| 1818 | impl AstNode for $ast { |
| 1819 | type Language = Lang; |
| 1820 | |
| 1821 | fn can_cast(kind: SyntaxKind) -> bool { |
| 1822 | kind == $kind |
| 1823 | } |
| 1824 | |
| 1825 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
| 1826 | if Self::can_cast(syntax.kind()) { |
| 1827 | Some(Self(syntax)) |
| 1828 | } else { |
| 1829 | None |
| 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | fn syntax(&self) -> &SyntaxNode { |
| 1834 | &self.0 |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | impl $ast { |
| 1839 | /// Get the line number (0-indexed) where this node starts. |
| 1840 | pub fn line(&self) -> usize { |
| 1841 | line_col_at_offset(&self.0, self.0.text_range().start()).0 |
| 1842 | } |
| 1843 | |
| 1844 | /// Get the column number (0-indexed, in bytes) where this node starts. |
| 1845 | pub fn column(&self) -> usize { |
| 1846 | line_col_at_offset(&self.0, self.0.text_range().start()).1 |
| 1847 | } |
| 1848 | |
| 1849 | /// Get both line and column (0-indexed) where this node starts. |
| 1850 | /// Returns (line, column) where column is measured in bytes from the start of the line. |
| 1851 | pub fn line_col(&self) -> (usize, usize) { |
| 1852 | line_col_at_offset(&self.0, self.0.text_range().start()) |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | impl core::fmt::Display for $ast { |
| 1857 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> { |
| 1858 | write!(f, "{}", self.0.text()) |
| 1859 | } |
| 1860 | } |
| 1861 | }; |
| 1862 | } |
| 1863 | |
| 1864 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#, ROOTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ROOT#); |
| 1865 | |
| 1866 | impl Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# { |
| 1867 | /// Capture an independent snapshot of this makefile. |
| 1868 | /// |
| 1869 | /// The returned value shares the underlying immutable green-node data |
| 1870 | /// with `self` at the time of the call, but lives in its own mutable |
| 1871 | /// tree: subsequent mutations to `self` do not propagate to the snapshot. |
| 1872 | /// Pair with [`Self::tree_eq`] to detect later mutations. |
| 1873 | pub fn snapshotrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile]snapshot().(&self) -> Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile] { |
| 1874 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#(SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#0..greenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]green().().into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().())) |
| 1875 | } |
| 1876 | |
| 1877 | /// Returns true iff the syntax trees of `self` and `other` are |
| 1878 | /// value-equal. An O(1) pointer-identity fast path makes this free for |
| 1879 | /// trees that still share state with a recent `snapshot()`. |
| 1880 | pub fn tree_eqrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile]tree_eq().(&self, other: &Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile]) -> bool { |
| 1881 | let a = self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#0..greenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]green().(); |
| 1882 | let b = other.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#0..greenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]green().(); |
| 1883 | let a_ref: &rowanrust-analyzer cargo rowan 0.16.1 crate/::GreenNodeDatarust-analyzer cargo rowan 0.16.1 green/node/GreenNodeData# = &a; |
| 1884 | let b_ref: &rowanrust-analyzer cargo rowan 0.16.1 crate/::GreenNodeDatarust-analyzer cargo rowan 0.16.1 green/node/GreenNodeData# = &b; |
| 1885 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/eq().(a_ref as *const _, b_ref as *const _) || a_ref 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().b_ref |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#, RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#); |
| 1890 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(Reciperust-analyzer cargo makefile-lossless 0.3.40 lossless/Recipe#, RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#); |
| 1891 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(Identifierrust-analyzer cargo makefile-lossless 0.3.40 lossless/Identifier#, IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#); |
| 1892 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#, VARIABLErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VARIABLE#); |
| 1893 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#, INCLUDErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INCLUDE#); |
| 1894 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(Vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/Vpath#, VPATHrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VPATH#); |
| 1895 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(ArchiveMembersrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMembers#, ARCHIVE_MEMBERSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBERS#); |
| 1896 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(ArchiveMemberrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMember#, ARCHIVE_MEMBERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBER#); |
| 1897 | ast_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/ast_node!!(Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#, CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL#); |
| 1898 | |
| 1899 | /// A reference to a variable in the makefile, e.g. `$(FOO)` or `${BAR}`. |
| 1900 | /// |
| 1901 | /// This wraps an EXPR syntax node whose first token is `$` followed by `(` or `{`. |
| 1902 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 1903 | pub struct VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#(SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#); |
| 1904 | |
| 1905 | impl VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference# { |
| 1906 | /// Try to cast a syntax node into a VariableReference. |
| 1907 | /// |
| 1908 | /// Returns `Some` if the node is an EXPR whose first token is `$` followed by |
| 1909 | /// `(`, `{`, or an identifier (for single-character variables like `$X`). |
| 1910 | pub fn castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]cast().(syntax: SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]> { |
| 1911 | if syntax.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<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().EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR# { |
| 1912 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 1913 | } |
| 1914 | let mut tokens = syntax |
| 1915 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 1916 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|it| it.into_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_token().()); |
| 1917 | let first = tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 1918 | if first.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().DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR# { |
| 1919 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 1920 | } |
| 1921 | // Accept $(...), ${...}, or $X (single-char) |
| 1922 | tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 1923 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference](syntax)) |
| 1924 | } |
| 1925 | |
| 1926 | /// Get the syntax node backing this variable reference. |
| 1927 | pub fn syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]syntax().(&self) -> &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode# { |
| 1928 | &self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0. |
| 1929 | } |
| 1930 | |
| 1931 | /// Get the name of the referenced variable. |
| 1932 | /// |
| 1933 | /// For simple references like `$(FOO)`, returns `"FOO"`. |
| 1934 | /// For function calls like `$(wildcard *.c)`, returns `"wildcard"`. |
| 1935 | /// |
| 1936 | /// Note: Variable references inside recipes are not parsed into the syntax tree |
| 1937 | /// (recipes are stored as raw text). This only finds references in variable values, |
| 1938 | /// prerequisites, and targets. |
| 1939 | /// |
| 1940 | /// # Example |
| 1941 | /// ``` |
| 1942 | /// use makefile_lossless::Makefile; |
| 1943 | /// let makefile: Makefile = "CFLAGS = $(BASE_FLAGS) -Wall\n".parse().unwrap(); |
| 1944 | /// let refs: Vec<_> = makefile.variable_references().collect(); |
| 1945 | /// assert_eq!(refs[0].name(), Some("BASE_FLAGS".to_string())); |
| 1946 | /// ``` |
| 1947 | pub fn namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]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#> { |
| 1948 | // After $ and (, the first IDENTIFIER token is the variable/function name |
| 1949 | self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0. |
| 1950 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 1951 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|it| it.into_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_token().()) |
| 1952 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|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#) |
| 1953 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|t| t.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().()) |
| 1954 | } |
| 1955 | |
| 1956 | /// Check if this is a function call rather than a simple variable reference. |
| 1957 | /// |
| 1958 | /// Returns `true` if the content after the function name contains whitespace |
| 1959 | /// or commas, indicating arguments (e.g. `$(subst a,b,text)` vs `$(CC)`). |
| 1960 | /// |
| 1961 | /// # Example |
| 1962 | /// ``` |
| 1963 | /// use makefile_lossless::Makefile; |
| 1964 | /// let makefile: Makefile = "FILES = $(wildcard *.c)\n".parse().unwrap(); |
| 1965 | /// let refs: Vec<_> = makefile.variable_references().collect(); |
| 1966 | /// assert!(refs[0].is_function_call()); |
| 1967 | /// ``` |
| 1968 | pub fn is_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]is_function_call().(&self) -> bool { |
| 1969 | let mut tokens = self |
| 1970 | .0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0. |
| 1971 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 1972 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|it| it.into_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_token().()); |
| 1973 | |
| 1974 | // Skip $ and opening paren/brace |
| 1975 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dollar) = tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().() else { |
| 1976 | return false; |
| 1977 | }; |
| 1978 | if dollar.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().DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR# { |
| 1979 | return false; |
| 1980 | } |
| 1981 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(open) = tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().() else { |
| 1982 | return false; |
| 1983 | }; |
| 1984 | if open.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().LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# && open.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().LBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LBRACE# { |
| 1985 | return false; |
| 1986 | } |
| 1987 | |
| 1988 | // Skip the function name (first IDENTIFIER) |
| 1989 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().() else { |
| 1990 | return false; |
| 1991 | }; |
| 1992 | if ident.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().IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# { |
| 1993 | return false; |
| 1994 | } |
| 1995 | |
| 1996 | // If the next token is whitespace or comma, it's a function call |
| 1997 | match tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().() { |
| 1998 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(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().WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# || 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().COMMArust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMA#, |
| 1999 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => false, |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | /// Count the number of comma-separated arguments in a function call. |
| 2004 | /// |
| 2005 | /// Returns 0 for simple variable references. For function calls, counts |
| 2006 | /// the commas at depth 0 (not inside nested parentheses) plus 1. |
| 2007 | /// |
| 2008 | /// # Example |
| 2009 | /// ``` |
| 2010 | /// use makefile_lossless::Makefile; |
| 2011 | /// let makefile: Makefile = "X = $(subst a,b,text)\n".parse().unwrap(); |
| 2012 | /// let refs: Vec<_> = makefile.variable_references().collect(); |
| 2013 | /// assert_eq!(refs[0].argument_count(), 3); |
| 2014 | /// ``` |
| 2015 | pub fn argument_countrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_count().(&self) -> usize { |
| 2016 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]is_function_call().() { |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
| 2020 | let mut commas = 0; |
| 2021 | let mut depth = 0; |
| 2022 | let mut past_name = false; |
| 2023 | |
| 2024 | for element in self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() { |
| 2025 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = element.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() else { |
| 2026 | // Child nodes (nested EXPR) don't contain top-level commas |
| 2027 | continue; |
| 2028 | }; |
| 2029 | match token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() { |
| 2030 | IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().past_name => { |
| 2031 | past_name = true; |
| 2032 | } |
| 2033 | DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR# | LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# | LBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LBRACE# if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().past_name => {} |
| 2034 | LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# => depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1, |
| 2035 | RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN# if depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 => depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1, |
| 2036 | COMMArust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMA# if depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 && past_name => commas rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1, |
| 2037 | _ => {} |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | if past_name { |
| 2042 | commas 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 |
| 2043 | } else { |
| 2044 | 0 |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | /// Determine which argument (0-based) the given byte offset falls into. |
| 2049 | /// |
| 2050 | /// Returns `None` if the offset is not inside this reference or if this |
| 2051 | /// is not a function call. |
| 2052 | /// |
| 2053 | /// # Example |
| 2054 | /// ``` |
| 2055 | /// use makefile_lossless::Makefile; |
| 2056 | /// let makefile: Makefile = "X = $(subst a,b,text)\n".parse().unwrap(); |
| 2057 | /// let refs: Vec<_> = makefile.variable_references().collect(); |
| 2058 | /// // offset 12 is 'a' (first arg), offset 14 is 'b' (second arg), offset 16 is 't' (third arg) |
| 2059 | /// assert_eq!(refs[0].argument_index_at_offset(12), Some(0)); |
| 2060 | /// assert_eq!(refs[0].argument_index_at_offset(14), Some(1)); |
| 2061 | /// assert_eq!(refs[0].argument_index_at_offset(16), Some(2)); |
| 2062 | /// ``` |
| 2063 | pub fn argument_index_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_index_at_offset().(&self, offset: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 2064 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]is_function_call().() { |
| 2065 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 2066 | } |
| 2067 | |
| 2068 | let ref_start: usize = self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().().startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 2069 | let ref_end: usize = self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().().endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 2070 | if offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().ref_start || offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().ref_end { |
| 2071 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 2072 | } |
| 2073 | |
| 2074 | let mut arg_index = 0; |
| 2075 | let mut depth = 0; |
| 2076 | let mut past_name = false; |
| 2077 | |
| 2078 | for element in self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() { |
| 2079 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = element.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() else { |
| 2080 | continue; |
| 2081 | }; |
| 2082 | let token_end: usize = token.text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text_range().().endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 2083 | |
| 2084 | match token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() { |
| 2085 | IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().past_name => { |
| 2086 | past_name = true; |
| 2087 | } |
| 2088 | DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR# | LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# | LBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LBRACE# if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().past_name => {} |
| 2089 | LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# => depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1, |
| 2090 | RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN# if depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 => depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1, |
| 2091 | COMMArust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMA# if depth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 && past_name => { |
| 2092 | if offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().token_end { |
| 2093 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(arg_index); |
| 2094 | } |
| 2095 | arg_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 2096 | } |
| 2097 | _ => {} |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | if past_name { |
| 2102 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(arg_index) |
| 2103 | } else { |
| 2104 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | /// Get the line number (0-indexed) where this reference starts. |
| 2109 | pub fn linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]line().(&self) -> usize { |
| 2110 | line_col_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/line_col_at_offset().(&self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0., self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().().startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().()).0 |
| 2111 | } |
| 2112 | |
| 2113 | /// Get the column number (0-indexed, in bytes) where this reference starts. |
| 2114 | pub fn columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]column().(&self) -> usize { |
| 2115 | line_col_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/line_col_at_offset().(&self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0., self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().().startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().()).1 |
| 2116 | } |
| 2117 | |
| 2118 | /// Get both line and column (0-indexed) where this reference starts. |
| 2119 | pub fn line_colrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]line_col().(&self) -> (usize, usize) { |
| 2120 | line_col_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/line_col_at_offset().(&self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0., self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().().startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().()) |
| 2121 | } |
| 2122 | |
| 2123 | /// Get the text range of this reference in the source. |
| 2124 | pub fn text_rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]text_range().(&self) -> rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange# { |
| 2125 | self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().() |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference# { |
| 2130 | fn fmtrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 2131 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.0rust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#0..textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text().()) |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | impl Reciperust-analyzer cargo makefile-lossless 0.3.40 lossless/Recipe# { |
| 2136 | /// Get the text content of this recipe line (the command to execute) |
| 2137 | /// |
| 2138 | /// For single-line recipes, this returns the command text excluding the |
| 2139 | /// leading tab and trailing newline. |
| 2140 | /// |
| 2141 | /// For multi-line recipes (with backslash continuations), this returns the |
| 2142 | /// full text including the internal newlines and continuation-line indentation, |
| 2143 | /// but still excluding the leading tab of the first line and the final newline. |
| 2144 | /// This preserves the exact content needed for a lossless round-trip. |
| 2145 | /// |
| 2146 | /// For comment-only lines, this returns an empty string. |
| 2147 | pub fn textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 2148 | let tokens: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self |
| 2149 | .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().() |
| 2150 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 2151 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|it| it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().()) |
| 2152 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 2153 | |
| 2154 | if tokens.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 2155 | return Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 2156 | } |
| 2157 | |
| 2158 | // Skip the first token if it's the leading INDENT |
| 2159 | let start = if tokens.firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().().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 core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#) { |
| 2160 | 1 |
| 2161 | } else { |
| 2162 | 0 |
| 2163 | }; |
| 2164 | |
| 2165 | // Skip the last token if it's the trailing NEWLINE |
| 2166 | let end = if tokens.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().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 core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#) { |
| 2167 | tokens.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1 |
| 2168 | } else { |
| 2169 | tokens.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 2170 | }; |
| 2171 | |
| 2172 | // Include TEXT, NEWLINE (internal continuation), and INDENT (continuation indent) tokens, |
| 2173 | // but skip COMMENT tokens (those are returned by comment()). |
| 2174 | // For INDENT tokens after a continuation newline, strip the leading tab character. |
| 2175 | let mut after_newline = false; |
| 2176 | tokens[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 2177 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 2178 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|t| match t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() { |
| 2179 | TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT# => { |
| 2180 | after_newline = false; |
| 2181 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t.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().()) |
| 2182 | } |
| 2183 | NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# => { |
| 2184 | after_newline = true; |
| 2185 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t.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().()) |
| 2186 | } |
| 2187 | INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT# if after_newline => { |
| 2188 | after_newline = false; |
| 2189 | // Strip the leading tab from continuation-line indentation |
| 2190 | let text = t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().(); |
| 2191 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(text.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().('\t').unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(text).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 2192 | } |
| 2193 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 2194 | }) |
| 2195 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 2196 | } |
| 2197 | |
| 2198 | /// Get the indentation string of this recipe line. |
| 2199 | /// |
| 2200 | /// Returns the leading indentation (typically a tab character) of this recipe line, |
| 2201 | /// or `None` if no indent token is present. |
| 2202 | /// |
| 2203 | /// # Example |
| 2204 | /// ``` |
| 2205 | /// use makefile_lossless::Makefile; |
| 2206 | /// |
| 2207 | /// let makefile: Makefile = "all:\n\techo hello\n".parse().unwrap(); |
| 2208 | /// let rule = makefile.rules().next().unwrap(); |
| 2209 | /// let recipe = rule.recipe_nodes().next().unwrap(); |
| 2210 | /// assert_eq!(recipe.indent(), Some("\t".to_string())); |
| 2211 | /// ``` |
| 2212 | pub fn indentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]indent().(&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#> { |
| 2213 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][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| { |
| 2214 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() { |
| 2215 | 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().INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT# { |
| 2216 | return 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().()); |
| 2217 | } |
| 2218 | } |
| 2219 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 2220 | }) |
| 2221 | } |
| 2222 | |
| 2223 | /// Get the comment content of this recipe line, if any |
| 2224 | /// |
| 2225 | /// Returns the comment text (including the '#' character) if this recipe |
| 2226 | /// line contains a comment, or None if there is no comment. |
| 2227 | /// |
| 2228 | /// # Example |
| 2229 | /// ``` |
| 2230 | /// use makefile_lossless::Makefile; |
| 2231 | /// |
| 2232 | /// let makefile: Makefile = "all:\n\t# This is a comment\n\techo hello\n".parse().unwrap(); |
| 2233 | /// let rule = makefile.rules().next().unwrap(); |
| 2234 | /// let recipes: Vec<_> = rule.recipe_nodes().collect(); |
| 2235 | /// assert_eq!(recipes[0].comment(), Some("# This is a comment".to_string())); |
| 2236 | /// assert_eq!(recipes[1].comment(), None); |
| 2237 | /// ``` |
| 2238 | pub fn commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]comment().(&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#> { |
| 2239 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().() |
| 2240 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 2241 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|it| { |
| 2242 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() { |
| 2243 | 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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# { |
| 2244 | return 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().()); |
| 2245 | } |
| 2246 | } |
| 2247 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 2248 | }) |
| 2249 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().() |
| 2250 | } |
| 2251 | |
| 2252 | /// Get the full content of this recipe line |
| 2253 | /// |
| 2254 | /// Returns all content including command text, comments, and internal whitespace, |
| 2255 | /// but excluding the leading indent. This is useful for getting the complete |
| 2256 | /// content of a recipe line regardless of whether it's a command, comment, or both. |
| 2257 | /// |
| 2258 | /// # Example |
| 2259 | /// ``` |
| 2260 | /// use makefile_lossless::Makefile; |
| 2261 | /// |
| 2262 | /// let makefile: Makefile = "all:\n\techo hello # inline comment\n".parse().unwrap(); |
| 2263 | /// let rule = makefile.rules().next().unwrap(); |
| 2264 | /// let recipe = rule.recipe_nodes().next().unwrap(); |
| 2265 | /// assert_eq!(recipe.full(), "echo hello # inline comment"); |
| 2266 | /// ``` |
| 2267 | pub fn fullrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]full().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 2268 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().() |
| 2269 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 2270 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|it| { |
| 2271 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() { |
| 2272 | // Include TEXT and COMMENT tokens, but skip INDENT and NEWLINE |
| 2273 | 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().TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT# || 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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# { |
| 2274 | return 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().()); |
| 2275 | } |
| 2276 | } |
| 2277 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 2278 | }) |
| 2279 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 2280 | .joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("") |
| 2281 | } |
| 2282 | |
| 2283 | /// Get the parent rule containing this recipe |
| 2284 | /// |
| 2285 | /// # Example |
| 2286 | /// ``` |
| 2287 | /// use makefile_lossless::Makefile; |
| 2288 | /// |
| 2289 | /// let makefile: Makefile = "all:\n\techo hello\n".parse().unwrap(); |
| 2290 | /// let rule = makefile.rules().next().unwrap(); |
| 2291 | /// let recipe = rule.recipe_nodes().next().unwrap(); |
| 2292 | /// let parent = recipe.parent().unwrap(); |
| 2293 | /// assert_eq!(parent.targets().collect::<Vec<_>>(), vec!["all"]); |
| 2294 | /// ``` |
| 2295 | pub fn parentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]parent().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> { |
| 2296 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][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().(Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]cast().) |
| 2297 | } |
| 2298 | |
| 2299 | /// Get the source range of this recipe node. |
| 2300 | pub fn text_rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text_range().(&self) -> rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange# { |
| 2301 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().().text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().() |
| 2302 | } |
| 2303 | |
| 2304 | /// Check if this recipe has the silent prefix (@) |
| 2305 | /// |
| 2306 | /// # Example |
| 2307 | /// ``` |
| 2308 | /// use makefile_lossless::Makefile; |
| 2309 | /// |
| 2310 | /// let makefile: Makefile = "all:\n\t@echo hello\n\techo world\n".parse().unwrap(); |
| 2311 | /// let rule = makefile.rules().next().unwrap(); |
| 2312 | /// let recipes: Vec<_> = rule.recipe_nodes().collect(); |
| 2313 | /// assert!(recipes[0].is_silent()); |
| 2314 | /// assert!(!recipes[1].is_silent()); |
| 2315 | /// ``` |
| 2316 | pub fn is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().(&self) -> bool { |
| 2317 | let text = self.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(); |
| 2318 | text.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('@') || text.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("-@") || text.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("+@") |
| 2319 | } |
| 2320 | |
| 2321 | /// Check if this recipe has the ignore-errors prefix (-) |
| 2322 | /// |
| 2323 | /// # Example |
| 2324 | /// ``` |
| 2325 | /// use makefile_lossless::Makefile; |
| 2326 | /// |
| 2327 | /// let makefile: Makefile = "all:\n\t-echo hello\n\techo world\n".parse().unwrap(); |
| 2328 | /// let rule = makefile.rules().next().unwrap(); |
| 2329 | /// let recipes: Vec<_> = rule.recipe_nodes().collect(); |
| 2330 | /// assert!(recipes[0].is_ignore_errors()); |
| 2331 | /// assert!(!recipes[1].is_ignore_errors()); |
| 2332 | /// ``` |
| 2333 | pub fn is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().(&self) -> bool { |
| 2334 | let text = self.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(); |
| 2335 | text.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('-') || text.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("@-") || text.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("+-") |
| 2336 | } |
| 2337 | |
| 2338 | /// Set the command prefix for this recipe |
| 2339 | /// |
| 2340 | /// The prefix can contain `@` (silent), `-` (ignore errors), and/or `+` (always execute). |
| 2341 | /// Pass an empty string to remove all prefixes. |
| 2342 | /// |
| 2343 | /// # Example |
| 2344 | /// ``` |
| 2345 | /// use makefile_lossless::Makefile; |
| 2346 | /// |
| 2347 | /// let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap(); |
| 2348 | /// let rule = makefile.rules().next().unwrap(); |
| 2349 | /// let mut recipe = rule.recipe_nodes().next().unwrap(); |
| 2350 | /// recipe.set_prefix("@"); |
| 2351 | /// assert_eq!(recipe.text(), "@echo hello"); |
| 2352 | /// assert!(recipe.is_silent()); |
| 2353 | /// ``` |
| 2354 | pub fn set_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]set_prefix().(&mut self, prefix: &str) { |
| 2355 | let text = self.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(); |
| 2356 | |
| 2357 | // Strip existing prefix characters |
| 2358 | let stripped = text.trim_start_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start_matches().(['@', '-', '+']); |
| 2359 | |
| 2360 | // Build new text with the new prefix |
| 2361 | let new_text = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}", prefix, stripped); |
| 2362 | |
| 2363 | self.replace_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]replace_text().(&new_text); |
| 2364 | } |
| 2365 | |
| 2366 | /// Replace the text content of this recipe line |
| 2367 | /// |
| 2368 | /// # Example |
| 2369 | /// ``` |
| 2370 | /// use makefile_lossless::Makefile; |
| 2371 | /// |
| 2372 | /// let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap(); |
| 2373 | /// let rule = makefile.rules().next().unwrap(); |
| 2374 | /// let mut recipe = rule.recipe_nodes().next().unwrap(); |
| 2375 | /// recipe.replace_text("echo world"); |
| 2376 | /// assert_eq!(recipe.text(), "echo world"); |
| 2377 | /// ``` |
| 2378 | pub fn replace_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]replace_text().(&mut self, new_text: &str) { |
| 2379 | let node = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().(); |
| 2380 | let parent = node.parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Recipe node must have a parent"); |
| 2381 | let node_index = node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().(); |
| 2382 | |
| 2383 | // Build a new RECIPE node with the new text |
| 2384 | 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().(); |
| 2385 | builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 2386 | |
| 2387 | // Preserve the existing INDENT token if present |
| 2388 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(indent_token) = node |
| 2389 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 2390 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|it| it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().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().INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false)) |
| 2391 | { |
| 2392 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), indent_token.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().().textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().()); |
| 2393 | } else { |
| 2394 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\t"); |
| 2395 | } |
| 2396 | |
| 2397 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), new_text); |
| 2398 | |
| 2399 | // Preserve the existing NEWLINE token if present |
| 2400 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(newline_token) = node |
| 2401 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 2402 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|it| it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().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().NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false)) |
| 2403 | { |
| 2404 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), newline_token.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().().textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().()); |
| 2405 | } else { |
| 2406 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n"); |
| 2407 | } |
| 2408 | |
| 2409 | builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 2410 | let new_syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/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().()); |
| 2411 | |
| 2412 | // Replace the old node with the new one |
| 2413 | parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(node_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#node_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_syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]); |
| 2414 | |
| 2415 | // Update self to point to the new node |
| 2416 | // Note: index() returns position among all siblings (nodes + tokens) |
| 2417 | // so we need to use children_with_tokens() and filter for the node |
| 2418 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = parent |
| 2419 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 2420 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(node_index) |
| 2421 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|element| element.into_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_node().()) |
| 2422 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Reciperust-analyzer cargo makefile-lossless 0.3.40 lossless/Recipe#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]cast().) |
| 2423 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("New recipe node should exist at the same index"); |
| 2424 | } |
| 2425 | |
| 2426 | /// Insert a new recipe line before this one |
| 2427 | /// |
| 2428 | /// # Example |
| 2429 | /// ``` |
| 2430 | /// use makefile_lossless::Makefile; |
| 2431 | /// |
| 2432 | /// let mut makefile: Makefile = "all:\n\techo world\n".parse().unwrap(); |
| 2433 | /// let mut rule = makefile.rules().next().unwrap(); |
| 2434 | /// let mut recipe = rule.recipe_nodes().next().unwrap(); |
| 2435 | /// recipe.insert_before("echo hello"); |
| 2436 | /// assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo hello", "echo world"]); |
| 2437 | /// ``` |
| 2438 | pub fn insert_beforerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_before().(&self, text: &str) { |
| 2439 | let node = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().(); |
| 2440 | let parent = node.parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Recipe node must have a parent"); |
| 2441 | let node_index = node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().(); |
| 2442 | |
| 2443 | // Build a new RECIPE node |
| 2444 | 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().(); |
| 2445 | builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 2446 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\t"); |
| 2447 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), text); |
| 2448 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n"); |
| 2449 | builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 2450 | let new_syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/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().()); |
| 2451 | |
| 2452 | // Insert before this recipe |
| 2453 | parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(node_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#node_index, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]); |
| 2454 | } |
| 2455 | |
| 2456 | /// Insert a new recipe line after this one |
| 2457 | /// |
| 2458 | /// # Example |
| 2459 | /// ``` |
| 2460 | /// use makefile_lossless::Makefile; |
| 2461 | /// |
| 2462 | /// let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap(); |
| 2463 | /// let mut rule = makefile.rules().next().unwrap(); |
| 2464 | /// let mut recipe = rule.recipe_nodes().next().unwrap(); |
| 2465 | /// recipe.insert_after("echo world"); |
| 2466 | /// assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo hello", "echo world"]); |
| 2467 | /// ``` |
| 2468 | pub fn insert_afterrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_after().(&self, text: &str) { |
| 2469 | let node = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().(); |
| 2470 | let parent = node.parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Recipe node must have a parent"); |
| 2471 | let node_index = node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().(); |
| 2472 | |
| 2473 | // Build a new RECIPE node |
| 2474 | 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().(); |
| 2475 | builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 2476 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\t"); |
| 2477 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), text); |
| 2478 | builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n"); |
| 2479 | builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().(); |
| 2480 | let new_syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/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().()); |
| 2481 | |
| 2482 | // Insert after this recipe |
| 2483 | parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(node_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..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#node_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_syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]); |
| 2484 | } |
| 2485 | |
| 2486 | /// Remove this recipe line from its parent |
| 2487 | /// |
| 2488 | /// # Example |
| 2489 | /// ``` |
| 2490 | /// use makefile_lossless::Makefile; |
| 2491 | /// |
| 2492 | /// let mut makefile: Makefile = "all:\n\techo hello\n\techo world\n".parse().unwrap(); |
| 2493 | /// let mut rule = makefile.rules().next().unwrap(); |
| 2494 | /// let mut recipe = rule.recipe_nodes().next().unwrap(); |
| 2495 | /// recipe.remove(); |
| 2496 | /// assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo world"]); |
| 2497 | /// ``` |
| 2498 | pub fn removerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]remove().(&self) { |
| 2499 | let node = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().(); |
| 2500 | let parent = node.parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Recipe node must have a parent"); |
| 2501 | let node_index = node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().(); |
| 2502 | |
| 2503 | // Remove this recipe node from its parent |
| 2504 | parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(node_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#node_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!![]); |
| 2505 | } |
| 2506 | |
| 2507 | /// Iterate `$(VAR)` and `${VAR}` variable references inside this recipe. |
| 2508 | /// |
| 2509 | /// Recipe bodies are stored as raw text, so [`Makefile::variable_references`] |
| 2510 | /// does not descend into them. This method scans the recipe's text directly |
| 2511 | /// and yields each reference with its absolute source range. |
| 2512 | /// |
| 2513 | /// Function calls (`$(shell ...)`, anything with whitespace or commas after |
| 2514 | /// the name) and automatic variables (`$@`, `$<`, numeric `$1`) are skipped; |
| 2515 | /// only plain variable references are returned. |
| 2516 | /// |
| 2517 | /// # Example |
| 2518 | /// ``` |
| 2519 | /// use makefile_lossless::Makefile; |
| 2520 | /// |
| 2521 | /// let makefile: Makefile = "all:\n\techo $(FOO) ${BAR}\n".parse().unwrap(); |
| 2522 | /// let rule = makefile.rules().next().unwrap(); |
| 2523 | /// let recipe = rule.recipe_nodes().next().unwrap(); |
| 2524 | /// let names: Vec<_> = recipe |
| 2525 | /// .variable_references() |
| 2526 | /// .iter() |
| 2527 | /// .map(|r| r.name().to_string()) |
| 2528 | /// .collect(); |
| 2529 | /// assert_eq!(names, vec!["FOO", "BAR"]); |
| 2530 | /// ``` |
| 2531 | pub fn variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]variable_references().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RecipeVariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#> { |
| 2532 | let mut out = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 2533 | for token in self |
| 2534 | .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().() |
| 2535 | .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() |
| 2536 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|it| it.into_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_token().()) |
| 2537 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|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().TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#) |
| 2538 | { |
| 2539 | let base: u32 = token.text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text_range().().startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 2540 | scan_recipe_variable_refsrust-analyzer cargo makefile-lossless 0.3.40 lossless/scan_recipe_variable_refs().(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().(), base, &mut out); |
| 2541 | } |
| 2542 | out |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | /// A `$(VAR)` or `${VAR}` reference found inside a recipe body. |
| 2547 | /// |
| 2548 | /// Recipes are stored as raw text, so these references have no backing syntax |
| 2549 | /// node; this type carries just the variable name and its absolute source range. |
| 2550 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 2551 | pub struct RecipeVariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference# { |
| 2552 | namerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 2553 | rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#range.: rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#, |
| 2554 | } |
| 2555 | |
| 2556 | impl RecipeVariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference# { |
| 2557 | /// The referenced variable name (without the surrounding `$(...)`). |
| 2558 | pub fn namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]name().(&self) -> &str { |
| 2559 | &self.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#name. |
| 2560 | } |
| 2561 | |
| 2562 | /// The absolute source range covering just the variable name. |
| 2563 | pub fn text_rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]text_range().(&self) -> rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange# { |
| 2564 | self.rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#range. |
| 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | /// Scan `text` for `$(VAR)` / `${VAR}` references, pushing each onto `out` with |
| 2569 | /// ranges offset by `base` (the absolute start of `text` in the source). |
| 2570 | fn scan_recipe_variable_refsrust-analyzer cargo makefile-lossless 0.3.40 lossless/scan_recipe_variable_refs().(text: &str, base: u32, out: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RecipeVariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#>) { |
| 2571 | let bytes = text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 2572 | let mut i = 0; |
| 2573 | while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 2574 | if bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().b'$' || i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 2575 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 2576 | continue; |
| 2577 | } |
| 2578 | let close = match bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`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]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). { |
| 2579 | b'(' => b')', |
| 2580 | b'{' => b'}', |
| 2581 | _ => { |
| 2582 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().2; |
| 2583 | continue; |
| 2584 | } |
| 2585 | }; |
| 2586 | let name_start = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2; |
| 2587 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rel_end) = bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().name_start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|&b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().close) else { |
| 2588 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().2; |
| 2589 | continue; |
| 2590 | }; |
| 2591 | let name_end = name_start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().rel_end; |
| 2592 | let name = &text[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().name_start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#name_end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 2593 | // Skip function calls like $(shell ...): a name with whitespace inside. |
| 2594 | if name.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() || name.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(char::is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().) { |
| 2595 | i = name_end 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; |
| 2596 | continue; |
| 2597 | } |
| 2598 | // Skip pure-numeric automatic variables ($1, $2, ...). |
| 2599 | if name.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|c| c.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().()) { |
| 2600 | i = name_end 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; |
| 2601 | continue; |
| 2602 | } |
| 2603 | out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(RecipeVariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference# { |
| 2604 | namerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#name.: name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 2605 | rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#range.: rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().( |
| 2606 | rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#::fromrust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`From<u32>`]from().(base rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().name_start as u32), |
| 2607 | rowanrust-analyzer cargo rowan 0.16.1 crate/::TextSizerust-analyzer cargo text-size 1.1.1 size/TextSize#::fromrust-analyzer cargo text-size 1.1.1 size/impl#[TextSize][`From<u32>`]from().(base rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().name_end as u32), |
| 2608 | ), |
| 2609 | }); |
| 2610 | i = name_end 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; |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | /// |
| 2615 | /// This removes trailing NEWLINE tokens from the end of a RULE node to avoid |
| 2616 | /// extra blank lines at the end of a file when the last rule is removed. |
| 2617 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) fn trim_trailing_newlinesrust-analyzer cargo makefile-lossless 0.3.40 lossless/trim_trailing_newlines().(node: &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#) { |
| 2618 | // Collect all trailing NEWLINE tokens at the end of the rule and within RECIPE nodes |
| 2619 | let mut newlines_to_remove = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 2620 | let mut current = node.last_child_or_tokenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]last_child_or_token().(); |
| 2621 | |
| 2622 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element) = current { |
| 2623 | match &element { |
| 2624 | 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().NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# => { |
| 2625 | newlines_to_remove.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(token.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`][Clone]clone().()); |
| 2626 | current = token.prev_sibling_or_tokenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]prev_sibling_or_token().(); |
| 2627 | } |
| 2628 | 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#(n) if n.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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE# => { |
| 2629 | // Also check for trailing newlines in the RECIPE node |
| 2630 | let mut recipe_current = n.last_child_or_tokenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]last_child_or_token().(); |
| 2631 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(recipe_element) = recipe_current { |
| 2632 | match &recipe_element { |
| 2633 | 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().NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# => { |
| 2634 | newlines_to_remove.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(token.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`][Clone]clone().()); |
| 2635 | recipe_current = token.prev_sibling_or_tokenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]prev_sibling_or_token().(); |
| 2636 | } |
| 2637 | _ => break, |
| 2638 | } |
| 2639 | } |
| 2640 | break; // Stop after checking the last RECIPE node |
| 2641 | } |
| 2642 | _ => break, |
| 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | // Remove all but one trailing newline (keep at least one) |
| 2647 | // Remove from highest index to lowest to avoid index shifts |
| 2648 | if newlines_to_remove.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 { |
| 2649 | // Sort by index descending |
| 2650 | newlines_to_remove.sort_by_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by_key().(|t| stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Reverse#(t.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]index().())); |
| 2651 | |
| 2652 | for token in newlines_to_remove.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(newlines_to_remove.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1) { |
| 2653 | let parent = token.parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]parent().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 2654 | let idx = token.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]index().(); |
| 2655 | parent.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!![]); |
| 2656 | } |
| 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | /// Helper function to remove a node along with its preceding comments and up to 1 empty line. |
| 2661 | /// |
| 2662 | /// This walks backward from the node, removing: |
| 2663 | /// - The node itself |
| 2664 | /// - All preceding comments (COMMENT tokens) |
| 2665 | /// - Up to 1 empty line (consecutive NEWLINE tokens) |
| 2666 | /// - Any WHITESPACE tokens between these elements |
| 2667 | pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) fn remove_with_preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 lossless/remove_with_preceding_comments().(node: &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#, parent: &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#) { |
| 2668 | let mut collected_elements = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 2669 | let mut found_comment = false; |
| 2670 | |
| 2671 | // Walk backward to collect preceding comments, newlines, and whitespace |
| 2672 | let mut current = node.prev_sibling_or_tokenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]prev_sibling_or_token().(); |
| 2673 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element) = current { |
| 2674 | match &element { |
| 2675 | 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) => match token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() { |
| 2676 | COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# => { |
| 2677 | if token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("#!") { |
| 2678 | break; // Don't remove shebang lines |
| 2679 | } |
| 2680 | found_comment = true; |
| 2681 | collected_elements.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element.clonerust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`][Clone]clone().()); |
| 2682 | } |
| 2683 | NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# | WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# => { |
| 2684 | collected_elements.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element.clonerust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`][Clone]clone().()); |
| 2685 | } |
| 2686 | _ => break, // Hit something else, stop |
| 2687 | }, |
| 2688 | 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#(n) => { |
| 2689 | // Handle BLANK_LINE nodes which wrap newlines |
| 2690 | if n.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().BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE# { |
| 2691 | collected_elements.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element.clonerust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`][Clone]clone().()); |
| 2692 | } else { |
| 2693 | break; // Hit another node type, stop |
| 2694 | } |
| 2695 | } |
| 2696 | } |
| 2697 | current = element.prev_sibling_or_tokenrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<L>>`]prev_sibling_or_token().(); |
| 2698 | } |
| 2699 | |
| 2700 | // Determine which preceding elements to remove |
| 2701 | // If we found comments, remove them along with up to 1 blank line |
| 2702 | let mut elements_to_remove = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 2703 | let mut consecutive_newlines = 0; |
| 2704 | for element in collected_elements.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() { |
| 2705 | let should_remove = match element { |
| 2706 | 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) => match token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() { |
| 2707 | COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# => { |
| 2708 | consecutive_newlines = 0; |
| 2709 | found_comment |
| 2710 | } |
| 2711 | NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# => { |
| 2712 | consecutive_newlines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 2713 | found_comment && consecutive_newlines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().1 |
| 2714 | } |
| 2715 | WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# => found_comment, |
| 2716 | _ => false, |
| 2717 | }, |
| 2718 | 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#(n) => { |
| 2719 | // Handle BLANK_LINE nodes (count as newlines) |
| 2720 | if n.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().BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE# { |
| 2721 | consecutive_newlines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 2722 | found_comment && consecutive_newlines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().1 |
| 2723 | } else { |
| 2724 | false |
| 2725 | } |
| 2726 | } |
| 2727 | }; |
| 2728 | |
| 2729 | if should_remove { |
| 2730 | elements_to_remove.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element.clonerust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`][Clone]clone().()); |
| 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | // Remove elements in reverse order (from highest index to lowest) to avoid index shifts |
| 2735 | // Start with the node itself, then preceding elements |
| 2736 | let mut all_to_remove = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![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.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().())]; |
| 2737 | all_to_remove.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(elements_to_remove.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().()); |
| 2738 | |
| 2739 | // Sort by index in descending order |
| 2740 | all_to_remove.sort_by_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by_key().(|el| stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Reverse#(el.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<L>>`]index().())); |
| 2741 | |
| 2742 | for element in all_to_remove { |
| 2743 | let idx = element.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<L>>`]index().(); |
| 2744 | parent.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!![]); |
| 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# { |
| 2749 | type Errrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][FromStr]Err# = craterust-analyzer cargo makefile-lossless 0.3.40 crate/::Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#; |
| 2750 | |
| 2751 | fn from_strrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][FromStr], Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 2752 | Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#::parserust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]parse().(s).to_rule_resultrust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<Rule>`]to_rule_result().() |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# { |
| 2757 | type Errrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][FromStr]Err# = craterust-analyzer cargo makefile-lossless 0.3.40 crate/::Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#; |
| 2758 | |
| 2759 | fn from_strrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][FromStr], Selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 2760 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::parserust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]parse().(s).to_resultrust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]to_result().() |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | #[cfg(test)] |
| 2765 | mod testsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/ { |
| 2766 | use superrust-analyzer cargo makefile-lossless 0.3.40 lossless/::*; |
| 2767 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::astrust-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#; |
| 2768 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/::matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().; |
| 2769 | |
| 2770 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2771 | fn test_conditionalsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditionals().() { |
| 2772 | // We'll use relaxed parsing for conditionals |
| 2773 | |
| 2774 | // Basic conditionals - ifdef/ifndef |
| 2775 | let code = "ifdef DEBUG\n DEBUG_FLAG := 1\nendif\n"; |
| 2776 | let mut buf = code.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 2777 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse basic ifdef"); |
| 2778 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("DEBUG_FLAG")); |
| 2779 | |
| 2780 | // Basic conditionals - ifeq/ifneq |
| 2781 | let code = |
| 2782 | "ifeq ($(OS),Windows_NT)\n RESULT := windows\nelse\n RESULT := unix\nendif\n"; |
| 2783 | let mut buf = code.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 2784 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse ifeq/ifneq"); |
| 2785 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("RESULT")); |
| 2786 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("windows")); |
| 2787 | |
| 2788 | // Nested conditionals with else |
| 2789 | let code = "ifdef DEBUG\n CFLAGS += -g\n ifdef VERBOSE\n CFLAGS += -v\n endif\nelse\n CFLAGS += -O2\nendif\n"; |
| 2790 | let mut buf = code.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 2791 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf) |
| 2792 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse nested conditionals with else"); |
| 2793 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("CFLAGS")); |
| 2794 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VERBOSE")); |
| 2795 | |
| 2796 | // Empty conditionals |
| 2797 | let code = "ifdef DEBUG\nendif\n"; |
| 2798 | let mut buf = code.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 2799 | let makefile = |
| 2800 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse empty conditionals"); |
| 2801 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 2802 | |
| 2803 | // Conditionals with else ifeq |
| 2804 | let code = "ifeq ($(OS),Windows)\n EXT := .exe\nelse ifeq ($(OS),Linux)\n EXT := .bin\nelse\n EXT := .out\nendif\n"; |
| 2805 | let mut buf = code.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 2806 | let makefile = |
| 2807 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse conditionals with else ifeq"); |
| 2808 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("EXT")); |
| 2809 | |
| 2810 | // Invalid conditionals - this should generate parse errors but still produce a Makefile |
| 2811 | let code = "ifXYZ DEBUG\nDEBUG := 1\nendif\n"; |
| 2812 | let mut buf = code.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 2813 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse with recovery"); |
| 2814 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("DEBUG")); |
| 2815 | |
| 2816 | // Missing condition - this should also generate parse errors but still produce a Makefile |
| 2817 | let code = "ifdef \nDEBUG := 1\nendif\n"; |
| 2818 | let mut buf = code.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 2819 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf) |
| 2820 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse with recovery - missing condition"); |
| 2821 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("DEBUG")); |
| 2822 | } |
| 2823 | |
| 2824 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2825 | fn test_variable_named_like_conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_named_like_conditional().() { |
| 2826 | // A variable whose name starts with "if" must not be mistaken for a |
| 2827 | // conditional directive (regression: `ifpkg` parsed as `ifdef`). |
| 2828 | let code = "ifpkg = $(if $(filter foo,bar),baz)\n"; |
| 2829 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("ifpkg variable should parse"); |
| 2830 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2831 | 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().(); |
| 2832 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 2833 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifpkg".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), 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().()); |
| 2834 | } |
| 2835 | |
| 2836 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2837 | fn test_conditional_with_trailing_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_with_trailing_comment().() { |
| 2838 | let code = "ifeq ($(X), linux) # extra features\nFOO = bar\nendif\n"; |
| 2839 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("trailing comment should parse"); |
| 2840 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2841 | } |
| 2842 | |
| 2843 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2844 | fn test_rule_with_continuation_in_targetsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_with_continuation_in_targets().() { |
| 2845 | let code = "a b \\\nc: dep\n\techo hi\n"; |
| 2846 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("continuation in targets should parse"); |
| 2847 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2848 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 2849 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 2850 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 2851 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "b".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "c".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 2852 | rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 2853 | ); |
| 2854 | } |
| 2855 | |
| 2856 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2857 | fn test_rule_with_indented_continuation_in_targetsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_with_indented_continuation_in_targets().() { |
| 2858 | // The continued target line is tab-indented; the indent delimits |
| 2859 | // targets rather than becoming part of the target name. |
| 2860 | let code = "a b \\\n\tc: dep\n\techo hi\n"; |
| 2861 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code |
| 2862 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 2863 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("indented target continuation should parse"); |
| 2864 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2865 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 2866 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 2867 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 2868 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "b".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "c".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 2869 | rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 2870 | ); |
| 2871 | } |
| 2872 | |
| 2873 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2874 | fn test_rule_with_continuation_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_with_continuation_in_prerequisites().() { |
| 2875 | // A prerequisite list continued onto a tab-indented line. The |
| 2876 | // continuation must not be folded into a prerequisite word, and the |
| 2877 | // continued prerequisites must still be recognised. |
| 2878 | let code = "all: a b \\\n\tc d\n\techo hi\n"; |
| 2879 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code |
| 2880 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 2881 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("prerequisite continuation should parse"); |
| 2882 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2883 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 2884 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 2885 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 2886 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 2887 | "a".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 2888 | "b".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 2889 | "c".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 2890 | "d".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 2891 | ], |
| 2892 | rules[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()..prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 2893 | ); |
| 2894 | } |
| 2895 | |
| 2896 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2897 | fn test_rule_prerequisite_escaped_backslash_not_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_prerequisite_escaped_backslash_not_continuation().() { |
| 2898 | // An escaped backslash (`\\`) ending a prerequisite line is a literal |
| 2899 | // backslash, not a continuation, so the next line is a recipe. |
| 2900 | let code = "all: a b\\\\\n\techo hi\n"; |
| 2901 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("escaped backslash should parse"); |
| 2902 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2903 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 2904 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 2905 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 2906 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "b\\\\".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 2907 | rules[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()..prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 2908 | ); |
| 2909 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 2910 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo hi".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 2911 | rules[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()..recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 2912 | ); |
| 2913 | } |
| 2914 | |
| 2915 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2916 | fn test_assignment_with_tab_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_assignment_with_tab_continuation().() { |
| 2917 | // A variable value continued onto a tab-indented line, as commonly |
| 2918 | // seen in debian/rules. The continuation must not be mistaken for a |
| 2919 | // recipe line (which previously produced a spurious "recipe line is |
| 2920 | // not attached to any target" error). |
| 2921 | let code = "NATIVE_ARCHS += alpha arc hppa \\\n\triscv64 sh4 sparc\n"; |
| 2922 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("tab continuation should parse"); |
| 2923 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2924 | 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().(); |
| 2925 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 2926 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("NATIVE_ARCHS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), 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().()); |
| 2927 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 2928 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("alpha arc hppa \\\n\triscv64 sh4 sparc".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 2929 | 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()..raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().() |
| 2930 | ); |
| 2931 | } |
| 2932 | |
| 2933 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2934 | fn test_assignment_escaped_backslash_not_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_assignment_escaped_backslash_not_continuation().() { |
| 2935 | // A value ending in an escaped backslash (`\\`) is a literal backslash, |
| 2936 | // not a line continuation, so the following line is not folded into the |
| 2937 | // value. An odd run of backslashes still continues the line. |
| 2938 | let code = "VAR = foo \\\\\n\tbar\n"; |
| 2939 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("escaped backslash should parse"); |
| 2940 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2941 | 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().(); |
| 2942 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 2943 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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().()), 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()..raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().()); |
| 2944 | |
| 2945 | let code = "VAR = foo \\\\\\\n\tbar\n"; |
| 2946 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("odd backslash run should parse"); |
| 2947 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2948 | 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().(); |
| 2949 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("foo \\\\\\\n\tbar".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), 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()..raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().()); |
| 2950 | } |
| 2951 | |
| 2952 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2953 | fn test_define_endefrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_define_endef().() { |
| 2954 | let code = "define greeting\n\techo hello\n\techo world\nendef\n\nall:\n\t$(greeting)\n"; |
| 2955 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("define/endef should parse"); |
| 2956 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2957 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()); |
| 2958 | } |
| 2959 | |
| 2960 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2961 | fn test_define_endef_nestedrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_define_endef_nested().() { |
| 2962 | let code = "define outer\ndefine inner\nbody\nendef\nendef\n"; |
| 2963 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = code.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("nested define/endef should parse"); |
| 2964 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 2965 | } |
| 2966 | |
| 2967 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2968 | fn test_parse_simplerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_simple().() { |
| 2969 | const SIMPLErust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/SIMPLE.: &str = r#"VARIABLE = value |
| 2970 | |
| 2971 | rule: dependency |
| 2972 | command |
| 2973 | "#; |
| 2974 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(SIMPLErust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/SIMPLE., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 2975 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 2976 | let node = parsed.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]syntax().(); |
| 2977 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 2978 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:#?}", node), |
| 2979 | r#"[email protected] |
| 2980 | [email protected] |
| 2981 | [email protected] "VARIABLE" |
| 2982 | [email protected] " " |
| 2983 | [email protected] "=" |
| 2984 | [email protected] " " |
| 2985 | [email protected] |
| 2986 | [email protected] "value" |
| 2987 | [email protected] "\n" |
| 2988 | [email protected] |
| 2989 | [email protected] "\n" |
| 2990 | [email protected] |
| 2991 | [email protected] |
| 2992 | [email protected] "rule" |
| 2993 | [email protected] ":" |
| 2994 | [email protected] " " |
| 2995 | [email protected] |
| 2996 | [email protected] |
| 2997 | [email protected] "dependency" |
| 2998 | [email protected] "\n" |
| 2999 | [email protected] |
| 3000 | [email protected] "\t" |
| 3001 | [email protected] "command" |
| 3002 | [email protected] "\n" |
| 3003 | "# |
| 3004 | ); |
| 3005 | |
| 3006 | let root = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3007 | |
| 3008 | let mut rules = root.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3009 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3010 | let rule = rules.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 3011 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 3012 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dependency"]); |
| 3013 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command"]); |
| 3014 | |
| 3015 | let mut variables = root.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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3016 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variables.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3017 | let variable = variables.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 3018 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable.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#("VARIABLE".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3019 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable.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().())); |
| 3020 | } |
| 3021 | |
| 3022 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3023 | fn test_parse_export_assignrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_export_assign().() { |
| 3024 | const EXPORTrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/EXPORT.: &str = r#"export VARIABLE := value |
| 3025 | "#; |
| 3026 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(EXPORTrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/EXPORT., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3027 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 3028 | let node = parsed.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]syntax().(); |
| 3029 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3030 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:#?}", node), |
| 3031 | r#"[email protected] |
| 3032 | [email protected] |
| 3033 | [email protected] "export" |
| 3034 | [email protected] " " |
| 3035 | [email protected] "VARIABLE" |
| 3036 | [email protected] " " |
| 3037 | [email protected] ":=" |
| 3038 | [email protected] " " |
| 3039 | [email protected] |
| 3040 | [email protected] "value" |
| 3041 | [email protected] "\n" |
| 3042 | "# |
| 3043 | ); |
| 3044 | |
| 3045 | let root = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3046 | |
| 3047 | let mut variables = root.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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3048 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variables.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3049 | let variable = variables.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 3050 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable.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#("VARIABLE".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3051 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(variable.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().())); |
| 3052 | } |
| 3053 | |
| 3054 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3055 | fn test_parse_multiple_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_multiple_prerequisites().() { |
| 3056 | const MULTIPLE_PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/MULTIPLE_PREREQUISITES.: &str = r#"rule: dependency1 dependency2 |
| 3057 | command |
| 3058 | |
| 3059 | "#; |
| 3060 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(MULTIPLE_PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/MULTIPLE_PREREQUISITES., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3061 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 3062 | let node = parsed.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]syntax().(); |
| 3063 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3064 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:#?}", node), |
| 3065 | r#"[email protected] |
| 3066 | [email protected] |
| 3067 | [email protected] |
| 3068 | [email protected] "rule" |
| 3069 | [email protected] ":" |
| 3070 | [email protected] " " |
| 3071 | [email protected] |
| 3072 | [email protected] |
| 3073 | [email protected] "dependency1" |
| 3074 | [email protected] " " |
| 3075 | [email protected] |
| 3076 | [email protected] "dependency2" |
| 3077 | [email protected] "\n" |
| 3078 | [email protected] |
| 3079 | [email protected] "\t" |
| 3080 | [email protected] "command" |
| 3081 | [email protected] "\n" |
| 3082 | [email protected] "\n" |
| 3083 | "# |
| 3084 | ); |
| 3085 | let root = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3086 | |
| 3087 | let rule = root.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 3088 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 3089 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3090 | rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3091 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dependency1", "dependency2"] |
| 3092 | ); |
| 3093 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command"]); |
| 3094 | } |
| 3095 | |
| 3096 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3097 | fn test_add_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_rule().() { |
| 3098 | 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().(); |
| 3099 | let rule = makefile.add_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_rule().("rule"); |
| 3100 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 3101 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3102 | rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3103 | Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().() |
| 3104 | ); |
| 3105 | |
| 3106 | 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().(), "rule:\n"); |
| 3107 | } |
| 3108 | |
| 3109 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3110 | fn test_add_rule_with_shebangrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_rule_with_shebang().() { |
| 3111 | // Regression test for bug where add_rule() panics on makefiles with shebangs |
| 3112 | let content = r#"#!/usr/bin/make -f |
| 3113 | |
| 3114 | build: blah |
| 3115 | $(MAKE) install |
| 3116 | |
| 3117 | clean: |
| 3118 | dh_clean |
| 3119 | "#; |
| 3120 | |
| 3121 | let mut makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3122 | let initial_count = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(); |
| 3123 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(initial_count, 2); |
| 3124 | |
| 3125 | // This should not panic |
| 3126 | let rule = makefile.add_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_rule().("build-indep"); |
| 3127 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["build-indep"]); |
| 3128 | |
| 3129 | // Should have one more rule now |
| 3130 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), initial_count +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1); |
| 3131 | } |
| 3132 | |
| 3133 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3134 | fn test_add_rule_formattingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_rule_formatting().() { |
| 3135 | // Regression test for formatting issues when adding rules |
| 3136 | let content = r#"build: blah |
| 3137 | $(MAKE) install |
| 3138 | |
| 3139 | clean: |
| 3140 | dh_clean |
| 3141 | "#; |
| 3142 | |
| 3143 | let mut makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3144 | let mut rule = makefile.add_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_rule().("build-indep"); |
| 3145 | rule.add_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_prerequisite().("build").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3146 | |
| 3147 | let expected = r#"build: blah |
| 3148 | $(MAKE) install |
| 3149 | |
| 3150 | clean: |
| 3151 | dh_clean |
| 3152 | |
| 3153 | build-indep: build |
| 3154 | "#; |
| 3155 | |
| 3156 | 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().(), expected); |
| 3157 | } |
| 3158 | |
| 3159 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3160 | fn test_push_commandrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_push_command().() { |
| 3161 | 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().(); |
| 3162 | let mut rule = makefile.add_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_rule().("rule"); |
| 3163 | |
| 3164 | // Add commands in place to the rule |
| 3165 | rule.push_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]push_command().("command"); |
| 3166 | rule.push_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]push_command().("command2"); |
| 3167 | |
| 3168 | // Check the commands in the rule |
| 3169 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3170 | rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3171 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command", "command2"] |
| 3172 | ); |
| 3173 | |
| 3174 | // Add a third command |
| 3175 | rule.push_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]push_command().("command3"); |
| 3176 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3177 | rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3178 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command", "command2", "command3"] |
| 3179 | ); |
| 3180 | |
| 3181 | // Check if the makefile was modified |
| 3182 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3183 | makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 3184 | "rule:\n\tcommand\n\tcommand2\n\tcommand3\n" |
| 3185 | ); |
| 3186 | |
| 3187 | // The rule should have the same string representation |
| 3188 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3189 | rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 3190 | "rule:\n\tcommand\n\tcommand2\n\tcommand3\n" |
| 3191 | ); |
| 3192 | } |
| 3193 | |
| 3194 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3195 | fn test_replace_commandrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_replace_command().() { |
| 3196 | 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().(); |
| 3197 | let mut rule = makefile.add_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_rule().("rule"); |
| 3198 | |
| 3199 | // Add commands in place |
| 3200 | rule.push_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]push_command().("command"); |
| 3201 | rule.push_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]push_command().("command2"); |
| 3202 | |
| 3203 | // Check the commands in the rule |
| 3204 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3205 | rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3206 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command", "command2"] |
| 3207 | ); |
| 3208 | |
| 3209 | // Replace the first command |
| 3210 | rule.replace_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]replace_command().(0, "new command"); |
| 3211 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3212 | rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3213 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new command", "command2"] |
| 3214 | ); |
| 3215 | |
| 3216 | // Check if the makefile was modified |
| 3217 | 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().(), "rule:\n\tnew command\n\tcommand2\n"); |
| 3218 | |
| 3219 | // The rule should have the same string representation |
| 3220 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "rule:\n\tnew command\n\tcommand2\n"); |
| 3221 | } |
| 3222 | |
| 3223 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3224 | fn test_replace_command_with_commentsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_replace_command_with_comments().() { |
| 3225 | // Regression test for bug where replace_command() inserts instead of replacing |
| 3226 | // when the rule contains comments |
| 3227 | let content = b"override_dh_strip:\n\t# no longer necessary after buster\n\tdh_strip --dbgsym-migration='amule-dbg (<< 1:2.3.2-2~)'\n"; |
| 3228 | |
| 3229 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&content[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3230 | |
| 3231 | let mut rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 3232 | |
| 3233 | // Before replacement, there should be 2 recipe nodes (comment + command) |
| 3234 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2); |
| 3235 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 3236 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), ""); // comment-only |
| 3237 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3238 | recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), |
| 3239 | "dh_strip --dbgsym-migration='amule-dbg (<< 1:2.3.2-2~)'" |
| 3240 | ); |
| 3241 | |
| 3242 | // Replace the second recipe (index 1, the actual command) |
| 3243 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.replace_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]replace_command().(1, "dh_strip")); |
| 3244 | |
| 3245 | // After replacement, there should still be 2 recipe nodes |
| 3246 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2); |
| 3247 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 3248 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), ""); // comment still there |
| 3249 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "dh_strip"); |
| 3250 | } |
| 3251 | |
| 3252 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3253 | fn test_parse_rule_without_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_rule_without_newline().() { |
| 3254 | let rule = "rule: dependency\n\tcommand".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3255 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 3256 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command"]); |
| 3257 | let rule = "rule: dependency".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3258 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 3259 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()); |
| 3260 | } |
| 3261 | |
| 3262 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3263 | fn test_parse_makefile_without_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_makefile_without_newline().() { |
| 3264 | let makefile = "rule: dependency\n\tcommand".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3265 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 3266 | } |
| 3267 | |
| 3268 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3269 | fn test_from_readerrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_from_reader().() { |
| 3270 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().("rule: dependency\n\tcommand".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3271 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 3272 | } |
| 3273 | |
| 3274 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3275 | fn test_parse_with_tab_after_last_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_with_tab_after_last_newline().() { |
| 3276 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().("rule: dependency\n\tcommand\n\t".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3277 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 3278 | } |
| 3279 | |
| 3280 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3281 | fn test_parse_with_space_after_last_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_with_space_after_last_newline().() { |
| 3282 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().("rule: dependency\n\tcommand\n ".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3283 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 3284 | } |
| 3285 | |
| 3286 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3287 | fn test_parse_with_comment_after_last_newlinerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_with_comment_after_last_newline().() { |
| 3288 | let makefile = |
| 3289 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().("rule: dependency\n\tcommand\n#comment".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3290 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 3291 | } |
| 3292 | |
| 3293 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3294 | fn test_parse_with_variable_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_with_variable_rule().() { |
| 3295 | let makefile = |
| 3296 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().("RULE := rule\n$(RULE): dependency\n\tcommand".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 3297 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3298 | |
| 3299 | // Check variable definition |
| 3300 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3301 | 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().(), 1); |
| 3302 | 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#("RULE".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3303 | 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()..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#("rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3304 | |
| 3305 | // Check rule |
| 3306 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3307 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3308 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["$(RULE)"]); |
| 3309 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3310 | rules[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()..prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3311 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dependency"] |
| 3312 | ); |
| 3313 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command"]); |
| 3314 | } |
| 3315 | |
| 3316 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3317 | fn test_parse_with_variable_dependencyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_with_variable_dependency().() { |
| 3318 | let makefile = |
| 3319 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().("DEP := dependency\nrule: $(DEP)\n\tcommand".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3320 | |
| 3321 | // Check variable definition |
| 3322 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3323 | 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().(), 1); |
| 3324 | 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#("DEP".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3325 | 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()..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#("dependency".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3326 | |
| 3327 | // Check rule |
| 3328 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3329 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3330 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 3331 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["$(DEP)"]); |
| 3332 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command"]); |
| 3333 | } |
| 3334 | |
| 3335 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3336 | fn test_parse_with_variable_commandrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_with_variable_command().() { |
| 3337 | let makefile = |
| 3338 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().("COM := command\nrule: dependency\n\t$(COM)".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3339 | |
| 3340 | // Check variable definition |
| 3341 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3342 | 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().(), 1); |
| 3343 | 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#("COM".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3344 | 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()..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#("command".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3345 | |
| 3346 | // Check rule |
| 3347 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3348 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3349 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 3350 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3351 | rules[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()..prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3352 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dependency"] |
| 3353 | ); |
| 3354 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["$(COM)"]); |
| 3355 | } |
| 3356 | |
| 3357 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3358 | fn test_regular_line_error_reportingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_regular_line_error_reporting().() { |
| 3359 | let input = "rule target\n\tcommand"; |
| 3360 | |
| 3361 | // Test both APIs with one input |
| 3362 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3363 | let direct_error = &parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.[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().; |
| 3364 | |
| 3365 | // Verify error is detected with correct details |
| 3366 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(direct_error.linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line., 2); |
| 3367 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3368 | direct_error.messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("expected"), |
| 3369 | "Error message should contain 'expected': {}", |
| 3370 | direct_error.messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message. |
| 3371 | ); |
| 3372 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(direct_error.contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context., "\tcommand"); |
| 3373 | |
| 3374 | // Check public API |
| 3375 | let reader_result = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().(input.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()); |
| 3376 | let parse_error = match reader_result { |
| 3377 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Parse error from from_reader"), |
| 3378 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => match err { |
| 3379 | selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/::Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(parse_err) => parse_err, |
| 3380 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Parse error"), |
| 3381 | }, |
| 3382 | }; |
| 3383 | |
| 3384 | // Verify formatting includes line number and context |
| 3385 | let error_text = parse_error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 3386 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(error_text.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Error at line 2:")); |
| 3387 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(error_text.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("2| \tcommand")); |
| 3388 | } |
| 3389 | |
| 3390 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3391 | fn test_parsing_error_context_with_bad_syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parsing_error_context_with_bad_syntax().() { |
| 3392 | // Input with unusual characters to ensure they're preserved |
| 3393 | let input = "#begin comment\n\t(╯°□°)╯︵ ┻━┻\n#end comment"; |
| 3394 | |
| 3395 | // With our relaxed parsing, verify we either get a proper error or parse successfully |
| 3396 | match Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().(input.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) { |
| 3397 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(makefile) => { |
| 3398 | // If it parses successfully, our parser is robust enough to handle unusual characters |
| 3399 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3400 | makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), |
| 3401 | 0, |
| 3402 | "Should not have found any rules" |
| 3403 | ); |
| 3404 | } |
| 3405 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => match err { |
| 3406 | selfrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/::Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(error) => { |
| 3407 | // Verify error details are properly reported |
| 3408 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(error.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line. >= 2, "Error line should be at least 2"); |
| 3409 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3410 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().error.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.[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()..contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().(), |
| 3411 | "Error context should not be empty" |
| 3412 | ); |
| 3413 | } |
| 3414 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Unexpected error type"), |
| 3415 | }, |
| 3416 | }; |
| 3417 | } |
| 3418 | |
| 3419 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3420 | fn test_error_message_formatrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_error_message_format().() { |
| 3421 | // Test the error formatter directly |
| 3422 | let parse_error = ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# { |
| 3423 | 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# { |
| 3424 | messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "test error".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 3425 | linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 42, |
| 3426 | contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "some problematic code".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 3427 | }], |
| 3428 | }; |
| 3429 | |
| 3430 | let error_text = parse_error.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 3431 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(error_text.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Error at line 42: test error")); |
| 3432 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(error_text.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("42| some problematic code")); |
| 3433 | } |
| 3434 | |
| 3435 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3436 | fn test_line_number_calculationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_line_number_calculation().() { |
| 3437 | // Test inputs for various error locations |
| 3438 | let test_cases = [ |
| 3439 | ("rule dependency\n\tcommand", 2), // Missing colon |
| 3440 | ("#comment\n\t(╯°□°)╯︵ ┻━┻", 2), // Strange characters |
| 3441 | ("var = value\n#comment\n\tindented line", 3), // Indented line not part of a rule |
| 3442 | ]; |
| 3443 | |
| 3444 | for (input, expected_line) in test_cases { |
| 3445 | // Attempt to parse the input |
| 3446 | match input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#>() { |
| 3447 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => { |
| 3448 | // If the parser succeeds, that's fine - our parser is more robust |
| 3449 | // Skip assertions when there's no error to check |
| 3450 | continue; |
| 3451 | } |
| 3452 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => { |
| 3453 | if let Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(parse_err) = err { |
| 3454 | // Verify error line number matches expected line |
| 3455 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3456 | parse_err.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line., expected_line, |
| 3457 | "Line number should match the expected line" |
| 3458 | ); |
| 3459 | |
| 3460 | // If the error is about indentation, check that the context includes the tab |
| 3461 | if parse_err.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.[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()..messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("indented") { |
| 3462 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3463 | parse_err.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.[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()..contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('\t'), |
| 3464 | "Context for indentation errors should include the tab character" |
| 3465 | ); |
| 3466 | } |
| 3467 | } else { |
| 3468 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected parse error, got: {:?}", err); |
| 3469 | } |
| 3470 | } |
| 3471 | } |
| 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3476 | fn test_conditional_featuresrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_features().() { |
| 3477 | // Simple use of variables in conditionals |
| 3478 | let code = r#" |
| 3479 | # Set variables based on DEBUG flag |
| 3480 | ifdef DEBUG |
| 3481 | CFLAGS += -g -DDEBUG |
| 3482 | else |
| 3483 | CFLAGS = -O2 |
| 3484 | endif |
| 3485 | |
| 3486 | # Define a build rule |
| 3487 | all: $(OBJS) |
| 3488 | $(CC) $(CFLAGS) -o $@ $^ |
| 3489 | "#; |
| 3490 | |
| 3491 | let mut buf = code.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 3492 | let makefile = |
| 3493 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse conditional features"); |
| 3494 | |
| 3495 | // Instead of checking for variable definitions which might not get created |
| 3496 | // due to conditionals, let's verify that we can parse the content without errors |
| 3497 | 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.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().(), "Makefile has content"); |
| 3498 | |
| 3499 | // Check that we detected a rule |
| 3500 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3501 | 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().rules.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Should have found rules"); |
| 3502 | |
| 3503 | // Verify conditional presence in the original code |
| 3504 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 3505 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 3506 | |
| 3507 | // Also try with an explicitly defined variable |
| 3508 | let code_with_var = r#" |
| 3509 | # Define a variable first |
| 3510 | CC = gcc |
| 3511 | |
| 3512 | ifdef DEBUG |
| 3513 | CFLAGS += -g -DDEBUG |
| 3514 | else |
| 3515 | CFLAGS = -O2 |
| 3516 | endif |
| 3517 | |
| 3518 | all: $(OBJS) |
| 3519 | $(CC) $(CFLAGS) -o $@ $^ |
| 3520 | "#; |
| 3521 | |
| 3522 | let mut buf = code_with_var.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 3523 | let makefile = |
| 3524 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse with explicit variable"); |
| 3525 | |
| 3526 | // Now we should definitely find at least the CC variable |
| 3527 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3528 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3529 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().vars.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 3530 | "Should have found at least the CC variable definition" |
| 3531 | ); |
| 3532 | } |
| 3533 | |
| 3534 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3535 | fn test_include_directiverust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_include_directive().() { |
| 3536 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().( |
| 3537 | "include config.mk\ninclude $(TOPDIR)/rules.mk\ninclude *.mk\n", |
| 3538 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 3539 | ); |
| 3540 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 3541 | let node = parsed.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]syntax().(); |
| 3542 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:#?}", node).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("INCLUDE@")); |
| 3543 | } |
| 3544 | |
| 3545 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3546 | fn test_export_variablesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_export_variables().() { |
| 3547 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().("export SHELL := /bin/bash\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3548 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 3549 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3550 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3551 | 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().(), 1); |
| 3552 | let shell_var = vars |
| 3553 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 3554 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|v| v.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("SHELL".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 3555 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 3556 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(shell_var.raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("bin/bash")); |
| 3557 | } |
| 3558 | |
| 3559 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3560 | fn test_bare_export_variablerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_bare_export_variable().() { |
| 3561 | // "export VARNAME" without assignment operator is a valid GNU Make directive |
| 3562 | // that exports a previously-defined variable. |
| 3563 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().( |
| 3564 | "DEB_CFLAGS_MAINT_APPEND = -Wno-error\nexport DEB_CFLAGS_MAINT_APPEND\n\n%:\n\tdh $@\n", |
| 3565 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 3566 | ); |
| 3567 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "errors: {:?}", parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.); |
| 3568 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3569 | // The bare export should be parsed as a variable, not a rule |
| 3570 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3571 | 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); |
| 3572 | // The pattern rule should be found |
| 3573 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3574 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3575 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t == "%")); |
| 3576 | // build-arch should match via the pattern rule |
| 3577 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("build-arch").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 3578 | } |
| 3579 | |
| 3580 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3581 | fn test_bare_export_at_eofrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_bare_export_at_eof().() { |
| 3582 | // Bare "export VARNAME" at end of file (no trailing newline) |
| 3583 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().("VAR = value\nexport VAR", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3584 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "errors: {:?}", parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.); |
| 3585 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3586 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3587 | 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); |
| 3588 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 3589 | } |
| 3590 | |
| 3591 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3592 | fn test_bare_export_does_not_eat_includerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_bare_export_does_not_eat_include().() { |
| 3593 | // Bare "export VARNAME" must not consume subsequent include directives |
| 3594 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().("VAR = value\nexport VAR\ninclude other.mk\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3595 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "errors: {:?}", parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.); |
| 3596 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3597 | 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); |
| 3598 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3599 | 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3600 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["other.mk"] |
| 3601 | ); |
| 3602 | } |
| 3603 | |
| 3604 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3605 | fn test_bare_export_multiplerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_bare_export_multiple().() { |
| 3606 | // Multiple bare exports in a row |
| 3607 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().( |
| 3608 | "A = 1\nB = 2\nexport A\nexport B\n\nall:\n\techo done\n", |
| 3609 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 3610 | ); |
| 3611 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "errors: {:?}", parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.); |
| 3612 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3613 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 4); |
| 3614 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3615 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3616 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t == "all")); |
| 3617 | } |
| 3618 | |
| 3619 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3620 | fn test_parse_error_does_not_cross_linesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_parse_error_does_not_cross_lines().() { |
| 3621 | // A line that fails to parse as a rule (no colon) must not |
| 3622 | // consume tokens from subsequent lines. |
| 3623 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().("notarule\n\nbuild-arch:\n\techo arch\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3624 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3625 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3626 | // The "notarule" line may produce an error, but build-arch must still be found |
| 3627 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3628 | rules.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t == "build-arch")), |
| 3629 | "build-arch rule should be parsed despite earlier error; rules: {:?}", |
| 3630 | rules |
| 3631 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 3632 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 3633 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 3634 | ); |
| 3635 | } |
| 3636 | |
| 3637 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3638 | fn test_pyfai_rules_fullrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_pyfai_rules_full().() { |
| 3639 | // Real-world pyFAI debian/rules that triggered #1131043 |
| 3640 | let input = "\ |
| 3641 | #!/usr/bin/make -f |
| 3642 | |
| 3643 | export DH_VERBOSE=1 |
| 3644 | export PYBUILD_NAME=pyfai |
| 3645 | |
| 3646 | DEB_CFLAGS_MAINT_APPEND = -Wno-error=incompatible-pointer-types |
| 3647 | export DEB_CFLAGS_MAINT_APPEND |
| 3648 | |
| 3649 | PY3VER := $(shell py3versions -dv) |
| 3650 | |
| 3651 | include /usr/share/dpkg/pkg-info.mk # sets SOURCE_DATE_EPOCH |
| 3652 | |
| 3653 | %: |
| 3654 | \tdh $@ --buildsystem=pybuild |
| 3655 | |
| 3656 | override_dh_auto_build-arch: |
| 3657 | \tPYBUILD_BUILD_ARGS=\"-Ccompile-args=--verbose\" dh_auto_build |
| 3658 | |
| 3659 | override_dh_auto_build-indep: override_dh_auto_build-arch |
| 3660 | \tsphinx-build -N -bhtml doc/source build/html |
| 3661 | |
| 3662 | override_dh_auto_test: |
| 3663 | |
| 3664 | execute_after_dh_auto_install: |
| 3665 | \tdh_install -p pyfai debian/python3-pyfai/usr/bin /usr |
| 3666 | "; |
| 3667 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3668 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3669 | |
| 3670 | // Include must be detected |
| 3671 | 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); |
| 3672 | |
| 3673 | // Pattern rule must be found |
| 3674 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3675 | makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("build-arch").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), |
| 3676 | "build-arch should match via %: pattern rule" |
| 3677 | ); |
| 3678 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3679 | makefile |
| 3680 | .find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("build-indep") |
| 3681 | .is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), |
| 3682 | "build-indep should match via %: pattern rule" |
| 3683 | ); |
| 3684 | |
| 3685 | // All override/execute_after rules must be found |
| 3686 | let rule_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>> = |
| 3687 | makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 3688 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3689 | rule_targets.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|t| t.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"%".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())), |
| 3690 | "missing %: rule; got: {:?}", |
| 3691 | rule_targets |
| 3692 | ); |
| 3693 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3694 | rule_targets |
| 3695 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 3696 | .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|t| t.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"override_dh_auto_build-arch".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())), |
| 3697 | "missing override_dh_auto_build-arch; got: {:?}", |
| 3698 | rule_targets |
| 3699 | ); |
| 3700 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3701 | rule_targets |
| 3702 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 3703 | .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|t| t.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"override_dh_auto_test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())), |
| 3704 | "missing override_dh_auto_test; got: {:?}", |
| 3705 | rule_targets |
| 3706 | ); |
| 3707 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3708 | rule_targets |
| 3709 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 3710 | .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|t| t.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"execute_after_dh_auto_install".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())), |
| 3711 | "missing execute_after_dh_auto_install; got: {:?}", |
| 3712 | rule_targets |
| 3713 | ); |
| 3714 | } |
| 3715 | |
| 3716 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3717 | fn test_variable_scopesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_scopes().() { |
| 3718 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().( |
| 3719 | "SIMPLE = value\nIMMEDIATE := value\nCONDITIONAL ?= value\nAPPEND += value\n", |
| 3720 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 3721 | ); |
| 3722 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 3723 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3724 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3725 | 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().(), 4); |
| 3726 | let var_names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = vars.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|v| v.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 3727 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var_names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"SIMPLE".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3728 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var_names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"IMMEDIATE".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3729 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var_names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"CONDITIONAL".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3730 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var_names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"APPEND".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3731 | } |
| 3732 | |
| 3733 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3734 | fn test_pattern_rule_parsingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_pattern_rule_parsing().() { |
| 3735 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().("%.o: %.c\n\t$(CC) -c -o $@ $<\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3736 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 3737 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3738 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3739 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3740 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "%.o"); |
| 3741 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rules[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()..recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("$@")); |
| 3742 | } |
| 3743 | |
| 3744 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3745 | fn test_include_variantsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_include_variants().() { |
| 3746 | // Test all variants of include directives |
| 3747 | let makefile_str = "include simple.mk\n-include optional.mk\nsinclude synonym.mk\ninclude $(VAR)/generated.mk\n"; |
| 3748 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(makefile_str, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3749 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 3750 | |
| 3751 | // Get the syntax tree for inspection |
| 3752 | let node = parsed.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]syntax().(); |
| 3753 | let debug_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:#?}", node); |
| 3754 | |
| 3755 | // Check that all includes are correctly parsed as INCLUDE nodes |
| 3756 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(debug_str.matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]matches().("INCLUDE@").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 4); |
| 3757 | |
| 3758 | // Check that we can access the includes through the AST |
| 3759 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3760 | |
| 3761 | // Count all child nodes that are INCLUDE kind |
| 3762 | let include_count = makefile |
| 3763 | .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().() |
| 3764 | .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().() |
| 3765 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|child| child.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().INCLUDErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INCLUDE#) |
| 3766 | .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(); |
| 3767 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(include_count, 4); |
| 3768 | |
| 3769 | // Test variable expansion in include paths |
| 3770 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile |
| 3771 | .included_filesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]included_files().() |
| 3772 | .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|path| path.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("$(VAR)"))); |
| 3773 | } |
| 3774 | |
| 3775 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3776 | fn test_include_apirust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_include_api().() { |
| 3777 | // Test the API for working with include directives |
| 3778 | let makefile_str = "include simple.mk\n-include optional.mk\nsinclude synonym.mk\n"; |
| 3779 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = makefile_str.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().(); |
| 3780 | |
| 3781 | // Test the includes method |
| 3782 | 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().(); |
| 3783 | 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().(), 3); |
| 3784 | |
| 3785 | // Test the is_optional method |
| 3786 | 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().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()..is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); // include |
| 3787 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(includes[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_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); // -include |
| 3788 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(includes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_optionalrust-analyzer cargo makefile-lossless 0.3.40 ast/include/impl#[Include]is_optional().()); // sinclude |
| 3789 | |
| 3790 | // Test the included_files method |
| 3791 | 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().(); |
| 3792 | 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!!["simple.mk", "optional.mk", "synonym.mk"]); |
| 3793 | |
| 3794 | // Test the path method on Include |
| 3795 | 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#("simple.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3796 | 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().1]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#("optional.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3797 | 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().2]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#("synonym.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 3798 | } |
| 3799 | |
| 3800 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3801 | fn test_include_integrationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_include_integration().() { |
| 3802 | // Test include directives in realistic makefile contexts |
| 3803 | |
| 3804 | // Case 1: With .PHONY (which was a source of the original issue) |
| 3805 | let phony_makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().( |
| 3806 | ".PHONY: build\n\nVERBOSE ?= 0\n\n# comment\n-include .env\n\nrule: dependency\n\tcommand" |
| 3807 | .as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().() |
| 3808 | ).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3809 | |
| 3810 | // We expect 2 rules: .PHONY and rule |
| 3811 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(phony_makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2); |
| 3812 | |
| 3813 | // But only one non-special rule (not starting with '.') |
| 3814 | let normal_rules_count = phony_makefile |
| 3815 | .rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().() |
| 3816 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|r| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('.'))) |
| 3817 | .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(); |
| 3818 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(normal_rules_count, 1); |
| 3819 | |
| 3820 | // Verify we have the include directive |
| 3821 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(phony_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); |
| 3822 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(phony_makefile.included_filesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]included_files().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), ".env"); |
| 3823 | |
| 3824 | // Case 2: Without .PHONY, just a regular rule and include |
| 3825 | let simple_makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().( |
| 3826 | "\n\nVERBOSE ?= 0\n\n# comment\n-include .env\n\nrule: dependency\n\tcommand" |
| 3827 | .as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), |
| 3828 | ) |
| 3829 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 3830 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(simple_makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 3831 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(simple_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); |
| 3832 | } |
| 3833 | |
| 3834 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3835 | fn test_real_conditional_directivesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_real_conditional_directives().() { |
| 3836 | // Basic if/else conditional |
| 3837 | let conditional = "ifdef DEBUG\nCFLAGS = -g\nelse\nCFLAGS = -O2\nendif\n"; |
| 3838 | let mut buf = conditional.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 3839 | let makefile = |
| 3840 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse basic if/else conditional"); |
| 3841 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 3842 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 3843 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else")); |
| 3844 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 3845 | |
| 3846 | // ifdef with nested ifdef |
| 3847 | let nested = "ifdef DEBUG\nCFLAGS = -g\nifdef VERBOSE\nCFLAGS += -v\nendif\nendif\n"; |
| 3848 | let mut buf = nested.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 3849 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse nested ifdef"); |
| 3850 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 3851 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 3852 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef VERBOSE")); |
| 3853 | |
| 3854 | // ifeq form |
| 3855 | let ifeq = "ifeq ($(OS),Windows_NT)\nTARGET = app.exe\nelse\nTARGET = app\nendif\n"; |
| 3856 | let mut buf = ifeq.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 3857 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse ifeq form"); |
| 3858 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 3859 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifeq")); |
| 3860 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Windows_NT")); |
| 3861 | } |
| 3862 | |
| 3863 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3864 | fn test_indented_text_outside_rulesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_indented_text_outside_rules().() { |
| 3865 | // Simple help target with echo commands |
| 3866 | let help_text = "help:\n\t@echo \"Available targets:\"\n\t@echo \" help show help\"\n"; |
| 3867 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(help_text, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3868 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 3869 | |
| 3870 | // Verify recipes are correctly parsed |
| 3871 | let root = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3872 | let rules = root.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3873 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 3874 | |
| 3875 | let help_rule = &rules[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().; |
| 3876 | let recipes = help_rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3877 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 3878 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[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()..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Available targets")); |
| 3879 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[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()..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("help")); |
| 3880 | } |
| 3881 | |
| 3882 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3883 | fn test_comment_handling_in_recipesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_comment_handling_in_recipes().() { |
| 3884 | // Create a recipe with a comment line |
| 3885 | let recipe_comment = "build:\n\t# This is a comment\n\tgcc -o app main.c\n"; |
| 3886 | |
| 3887 | // Parse the recipe |
| 3888 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(recipe_comment, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3889 | |
| 3890 | // Verify no parsing errors |
| 3891 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3892 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 3893 | "Should parse recipe with comments without errors" |
| 3894 | ); |
| 3895 | |
| 3896 | // Check rule structure |
| 3897 | let root = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3898 | let rules = root.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3899 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1, "Should find exactly one rule"); |
| 3900 | |
| 3901 | // Check the rule has the correct name |
| 3902 | let build_rule = &rules[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().; |
| 3903 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3904 | build_rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 3905 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["build"], |
| 3906 | "Rule should have 'build' as target" |
| 3907 | ); |
| 3908 | |
| 3909 | // Check recipes are parsed correctly |
| 3910 | // recipes() now returns all recipe nodes including comment-only lines |
| 3911 | let recipes = build_rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3912 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2, "Should find two recipe nodes"); |
| 3913 | |
| 3914 | // First recipe should be comment-only |
| 3915 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), ""); |
| 3916 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3917 | recipes[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()..commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]comment().(), |
| 3918 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("# This is a comment".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 3919 | ); |
| 3920 | |
| 3921 | // Second recipe should be the command |
| 3922 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "gcc -o app main.c"); |
| 3923 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]comment().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3924 | } |
| 3925 | |
| 3926 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3927 | fn test_multiline_variablesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_multiline_variables().() { |
| 3928 | // Simple multiline variable test |
| 3929 | let multiline = "SOURCES = main.c \\\n util.c\n"; |
| 3930 | |
| 3931 | // Parse the multiline variable |
| 3932 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(multiline, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3933 | |
| 3934 | // We can extract the variable even with errors (since backslash handling is not perfect) |
| 3935 | let root = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3936 | let vars = root.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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3937 | 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.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Should find at least one variable"); |
| 3938 | |
| 3939 | // Test other multiline variable forms |
| 3940 | |
| 3941 | // := assignment operator |
| 3942 | let operators = "CFLAGS := -Wall \\\n -Werror\n"; |
| 3943 | let parsed_operators = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(operators, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3944 | |
| 3945 | // Extract variable with := operator |
| 3946 | let root = parsed_operators.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3947 | let vars = root.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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3948 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3949 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().vars.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 3950 | "Should find at least one variable with := operator" |
| 3951 | ); |
| 3952 | |
| 3953 | // += assignment operator |
| 3954 | let append = "LDFLAGS += -L/usr/lib \\\n -lm\n"; |
| 3955 | let parsed_append = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(append, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3956 | |
| 3957 | // Extract variable with += operator |
| 3958 | let root = parsed_append.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3959 | let vars = root.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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3960 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 3961 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().vars.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 3962 | "Should find at least one variable with += operator" |
| 3963 | ); |
| 3964 | } |
| 3965 | |
| 3966 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 3967 | fn test_whitespace_and_eof_handlingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_whitespace_and_eof_handling().() { |
| 3968 | // Test 1: File ending with blank lines |
| 3969 | let blank_lines = "VAR = value\n\n\n"; |
| 3970 | |
| 3971 | let parsed_blank = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(blank_lines, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3972 | |
| 3973 | // We should be able to extract the variable definition |
| 3974 | let root = parsed_blank.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3975 | let vars = root.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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3976 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3977 | vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 3978 | 1, |
| 3979 | "Should find one variable in blank lines test" |
| 3980 | ); |
| 3981 | |
| 3982 | // Test 2: File ending with space |
| 3983 | let trailing_space = "VAR = value \n"; |
| 3984 | |
| 3985 | let parsed_space = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(trailing_space, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 3986 | |
| 3987 | // We should be able to extract the variable definition |
| 3988 | let root = parsed_space.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 3989 | let vars = root.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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 3990 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 3991 | vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 3992 | 1, |
| 3993 | "Should find one variable in trailing space test" |
| 3994 | ); |
| 3995 | |
| 3996 | // Test 3: No final newline |
| 3997 | let no_newline = "VAR = value"; |
| 3998 | |
| 3999 | let parsed_no_newline = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(no_newline, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4000 | |
| 4001 | // Regardless of parsing errors, we should be able to extract the variable |
| 4002 | let root = parsed_no_newline.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4003 | let vars = root.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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4004 | 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().(), 1, "Should find one variable in no newline test"); |
| 4005 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 4006 | 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().(), |
| 4007 | 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().()), |
| 4008 | "Variable name should be VAR" |
| 4009 | ); |
| 4010 | } |
| 4011 | |
| 4012 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4013 | fn test_complex_variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_complex_variable_references().() { |
| 4014 | // Simple function call |
| 4015 | let wildcard = "SOURCES = $(wildcard *.c)\n"; |
| 4016 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(wildcard, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4017 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4018 | |
| 4019 | // Nested variable reference |
| 4020 | let nested = "PREFIX = /usr\nBINDIR = $(PREFIX)/bin\n"; |
| 4021 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(nested, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4022 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4023 | |
| 4024 | // Function with complex arguments |
| 4025 | let patsubst = "OBJECTS = $(patsubst %.c,%.o,$(SOURCES))\n"; |
| 4026 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(patsubst, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4027 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4028 | } |
| 4029 | |
| 4030 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4031 | fn test_complex_variable_references_minimalrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_complex_variable_references_minimal().() { |
| 4032 | // Simple function call |
| 4033 | let wildcard = "SOURCES = $(wildcard *.c)\n"; |
| 4034 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(wildcard, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4035 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4036 | |
| 4037 | // Nested variable reference |
| 4038 | let nested = "PREFIX = /usr\nBINDIR = $(PREFIX)/bin\n"; |
| 4039 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(nested, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4040 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4041 | |
| 4042 | // Function with complex arguments |
| 4043 | let patsubst = "OBJECTS = $(patsubst %.c,%.o,$(SOURCES))\n"; |
| 4044 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(patsubst, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4045 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4046 | } |
| 4047 | |
| 4048 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4049 | fn test_multiline_variable_with_backslashrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_multiline_variable_with_backslash().() { |
| 4050 | let content = r#" |
| 4051 | LONG_VAR = This is a long variable \ |
| 4052 | that continues on the next line \ |
| 4053 | and even one more line |
| 4054 | "#; |
| 4055 | |
| 4056 | // For now, we'll use relaxed parsing since the backslash handling isn't fully implemented |
| 4057 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4058 | let makefile = |
| 4059 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse multiline variable"); |
| 4060 | |
| 4061 | // Check that we can extract the variable even with errors |
| 4062 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4063 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 4064 | vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 4065 | 1, |
| 4066 | "Expected 1 variable but found {}", |
| 4067 | vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 4068 | ); |
| 4069 | let var_value = 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()..raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().(); |
| 4070 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(var_value.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), "Variable value is None"); |
| 4071 | |
| 4072 | // The value might not be perfect due to relaxed parsing, but it should contain most of the content |
| 4073 | let value_str = var_value.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 4074 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4075 | value_str.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("long variable"), |
| 4076 | "Value doesn't contain expected content" |
| 4077 | ); |
| 4078 | } |
| 4079 | |
| 4080 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4081 | fn test_multiline_variable_with_mixed_operatorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_multiline_variable_with_mixed_operators().() { |
| 4082 | let content = r#" |
| 4083 | PREFIX ?= /usr/local |
| 4084 | CFLAGS := -Wall -O2 \ |
| 4085 | -I$(PREFIX)/include \ |
| 4086 | -DDEBUG |
| 4087 | "#; |
| 4088 | // Use relaxed parsing for now |
| 4089 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4090 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf) |
| 4091 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse multiline variable with operators"); |
| 4092 | |
| 4093 | // Check that we can extract variables even with errors |
| 4094 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4095 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4096 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().vars.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4097 | "Expected at least 1 variable, found {}", |
| 4098 | vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 4099 | ); |
| 4100 | |
| 4101 | // Check PREFIX variable |
| 4102 | let prefix_var = vars |
| 4103 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 4104 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|v| v.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."PREFIX"); |
| 4105 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(prefix_var.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), "Expected to find PREFIX variable"); |
| 4106 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4107 | prefix_var.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().raw_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]raw_value().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), |
| 4108 | "PREFIX variable has no value" |
| 4109 | ); |
| 4110 | |
| 4111 | // CFLAGS may be parsed incompletely but should exist in some form |
| 4112 | let cflags_var = vars |
| 4113 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 4114 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|v| v.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("CFLAGS")); |
| 4115 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4116 | cflags_var.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), |
| 4117 | "Expected to find CFLAGS variable (or part of it)" |
| 4118 | ); |
| 4119 | } |
| 4120 | |
| 4121 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4122 | fn test_indented_help_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_indented_help_text().() { |
| 4123 | let content = r#" |
| 4124 | .PHONY: help |
| 4125 | help: |
| 4126 | @echo "Available targets:" |
| 4127 | @echo " build - Build the project" |
| 4128 | @echo " test - Run tests" |
| 4129 | @echo " clean - Remove build artifacts" |
| 4130 | "#; |
| 4131 | // Use relaxed parsing for now |
| 4132 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4133 | let makefile = |
| 4134 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse indented help text"); |
| 4135 | |
| 4136 | // Check that we can extract rules even with errors |
| 4137 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4138 | 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().rules.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Expected at least one rule"); |
| 4139 | |
| 4140 | // Find help rule |
| 4141 | let help_rule = rules.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."help")); |
| 4142 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(help_rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), "Expected to find help rule"); |
| 4143 | |
| 4144 | // Check recipes - they might not be perfectly parsed but should exist |
| 4145 | let recipes = help_rule.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4146 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4147 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().recipes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4148 | "Expected at least one recipe line in help rule" |
| 4149 | ); |
| 4150 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4151 | recipes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|r| r.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Available targets")), |
| 4152 | "Expected to find 'Available targets' in recipes" |
| 4153 | ); |
| 4154 | } |
| 4155 | |
| 4156 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4157 | fn test_indented_lines_in_conditionalsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_indented_lines_in_conditionals().() { |
| 4158 | let content = r#" |
| 4159 | ifdef DEBUG |
| 4160 | CFLAGS += -g -DDEBUG |
| 4161 | # This is a comment inside conditional |
| 4162 | ifdef VERBOSE |
| 4163 | CFLAGS += -v |
| 4164 | endif |
| 4165 | endif |
| 4166 | "#; |
| 4167 | // Use relaxed parsing for conditionals with indented lines |
| 4168 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4169 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf) |
| 4170 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse indented lines in conditionals"); |
| 4171 | |
| 4172 | // Check that we detected conditionals |
| 4173 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 4174 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 4175 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef VERBOSE")); |
| 4176 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 4177 | } |
| 4178 | |
| 4179 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4180 | fn test_recipe_with_colonrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_with_colon().() { |
| 4181 | let content = r#" |
| 4182 | build: |
| 4183 | @echo "Building at: $(shell date)" |
| 4184 | gcc -o program main.c |
| 4185 | "#; |
| 4186 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(content, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4187 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4188 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4189 | "Failed to parse recipe with colon: {:?}", |
| 4190 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors. |
| 4191 | ); |
| 4192 | } |
| 4193 | |
| 4194 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4195 | fn test_double_colon_rulesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_double_colon_rules().() { |
| 4196 | let content = r#" |
| 4197 | %.o :: %.c |
| 4198 | $(CC) -c $< -o $@ |
| 4199 | |
| 4200 | # Double colon allows multiple rules for same target |
| 4201 | all:: prerequisite1 |
| 4202 | @echo "First rule for all" |
| 4203 | |
| 4204 | all:: prerequisite2 |
| 4205 | @echo "Second rule for all" |
| 4206 | "#; |
| 4207 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(content, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4208 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4209 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4210 | "Failed to parse double colon rules: {:?}", |
| 4211 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors. |
| 4212 | ); |
| 4213 | |
| 4214 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4215 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4216 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3); |
| 4217 | |
| 4218 | // All rules should be double-colon |
| 4219 | for rule in &rules { |
| 4220 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_double_colonrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]is_double_colon().()); |
| 4221 | } |
| 4222 | |
| 4223 | // Check targets |
| 4224 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["%.o"]); |
| 4225 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["all"]); |
| 4226 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["all"]); |
| 4227 | |
| 4228 | // Check prerequisites |
| 4229 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 4230 | rules[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()..prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 4231 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["prerequisite1"] |
| 4232 | ); |
| 4233 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 4234 | rules[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 4235 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["prerequisite2"] |
| 4236 | ); |
| 4237 | } |
| 4238 | |
| 4239 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4240 | fn test_else_conditional_directivesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_else_conditional_directives().() { |
| 4241 | // Test else ifeq |
| 4242 | let content = r#" |
| 4243 | ifeq ($(OS),Windows_NT) |
| 4244 | TARGET = windows |
| 4245 | else ifeq ($(OS),Darwin) |
| 4246 | TARGET = macos |
| 4247 | else ifeq ($(OS),Linux) |
| 4248 | TARGET = linux |
| 4249 | else |
| 4250 | TARGET = unknown |
| 4251 | endif |
| 4252 | "#; |
| 4253 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4254 | let makefile = |
| 4255 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse else ifeq directive"); |
| 4256 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else ifeq")); |
| 4257 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("TARGET")); |
| 4258 | |
| 4259 | // Test else ifdef |
| 4260 | let content = r#" |
| 4261 | ifdef WINDOWS |
| 4262 | TARGET = windows |
| 4263 | else ifdef DARWIN |
| 4264 | TARGET = macos |
| 4265 | else ifdef LINUX |
| 4266 | TARGET = linux |
| 4267 | else |
| 4268 | TARGET = unknown |
| 4269 | endif |
| 4270 | "#; |
| 4271 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4272 | let makefile = |
| 4273 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse else ifdef directive"); |
| 4274 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else ifdef")); |
| 4275 | |
| 4276 | // Test else ifndef |
| 4277 | let content = r#" |
| 4278 | ifndef NOWINDOWS |
| 4279 | TARGET = windows |
| 4280 | else ifndef NODARWIN |
| 4281 | TARGET = macos |
| 4282 | else |
| 4283 | TARGET = linux |
| 4284 | endif |
| 4285 | "#; |
| 4286 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4287 | let makefile = |
| 4288 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse else ifndef directive"); |
| 4289 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else ifndef")); |
| 4290 | |
| 4291 | // Test else ifneq |
| 4292 | let content = r#" |
| 4293 | ifneq ($(OS),Windows_NT) |
| 4294 | TARGET = not_windows |
| 4295 | else ifneq ($(OS),Darwin) |
| 4296 | TARGET = not_macos |
| 4297 | else |
| 4298 | TARGET = darwin |
| 4299 | endif |
| 4300 | "#; |
| 4301 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4302 | let makefile = |
| 4303 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse else ifneq directive"); |
| 4304 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else ifneq")); |
| 4305 | } |
| 4306 | |
| 4307 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4308 | fn test_complex_else_conditionalsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_complex_else_conditionals().() { |
| 4309 | // Test complex nested else conditionals with mixed types |
| 4310 | let content = r#"VAR1 := foo |
| 4311 | VAR2 := bar |
| 4312 | |
| 4313 | ifeq ($(VAR1),foo) |
| 4314 | RESULT := foo_matched |
| 4315 | else ifdef VAR2 |
| 4316 | RESULT := var2_defined |
| 4317 | else ifndef VAR3 |
| 4318 | RESULT := var3_not_defined |
| 4319 | else |
| 4320 | RESULT := final_else |
| 4321 | endif |
| 4322 | |
| 4323 | all: |
| 4324 | @echo $(RESULT) |
| 4325 | "#; |
| 4326 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4327 | let makefile = |
| 4328 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse complex else conditionals"); |
| 4329 | |
| 4330 | // Verify the structure is preserved |
| 4331 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 4332 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifeq ($(VAR1),foo)")); |
| 4333 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else ifdef VAR2")); |
| 4334 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else ifndef VAR3")); |
| 4335 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else")); |
| 4336 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 4337 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("RESULT")); |
| 4338 | |
| 4339 | // Verify rules are still parsed correctly |
| 4340 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4341 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 4342 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["all"]); |
| 4343 | } |
| 4344 | |
| 4345 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4346 | fn test_conditional_token_structurerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_token_structure().() { |
| 4347 | // Test that conditionals have proper token structure |
| 4348 | let content = r#"ifdef VAR1 |
| 4349 | X := 1 |
| 4350 | else ifdef VAR2 |
| 4351 | X := 2 |
| 4352 | else |
| 4353 | X := 3 |
| 4354 | endif |
| 4355 | "#; |
| 4356 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4357 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4358 | |
| 4359 | // Check that we can traverse the syntax tree |
| 4360 | let syntax = makefile.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().(); |
| 4361 | |
| 4362 | // Find CONDITIONAL nodes |
| 4363 | let mut found_conditional = false; |
| 4364 | let mut found_conditional_if = false; |
| 4365 | let mut found_conditional_else = false; |
| 4366 | let mut found_conditional_endif = false; |
| 4367 | |
| 4368 | fn check_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/check_node().( |
| 4369 | node: &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#, |
| 4370 | found_cond: &mut bool, |
| 4371 | found_if: &mut bool, |
| 4372 | found_else: &mut bool, |
| 4373 | found_endif: &mut bool, |
| 4374 | ) { |
| 4375 | match node.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() { |
| 4376 | SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL# => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().found_cond = true, |
| 4377 | SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::CONDITIONAL_IFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_IF# => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().found_if = true, |
| 4378 | SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::CONDITIONAL_ELSErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ELSE# => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().found_else = true, |
| 4379 | SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::CONDITIONAL_ENDIFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ENDIF# => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().found_endif = true, |
| 4380 | _ => {} |
| 4381 | } |
| 4382 | |
| 4383 | for child in node.childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().() { |
| 4384 | check_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/check_node().(&child, found_cond, found_if, found_else, found_endif); |
| 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | check_noderust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/check_node().( |
| 4389 | syntax, |
| 4390 | &mut found_conditional, |
| 4391 | &mut found_conditional_if, |
| 4392 | &mut found_conditional_else, |
| 4393 | &mut found_conditional_endif, |
| 4394 | ); |
| 4395 | |
| 4396 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(found_conditional, "Should have CONDITIONAL node"); |
| 4397 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(found_conditional_if, "Should have CONDITIONAL_IF node"); |
| 4398 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(found_conditional_else, "Should have CONDITIONAL_ELSE node"); |
| 4399 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4400 | found_conditional_endif, |
| 4401 | "Should have CONDITIONAL_ENDIF node" |
| 4402 | ); |
| 4403 | } |
| 4404 | |
| 4405 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4406 | fn test_ambiguous_assignment_vs_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_ambiguous_assignment_vs_rule().() { |
| 4407 | // Test case: Variable assignment with equals sign |
| 4408 | const VAR_ASSIGNMENTrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/VAR_ASSIGNMENT.: &str = "VARIABLE = value\n"; |
| 4409 | |
| 4410 | let mut buf = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(VAR_ASSIGNMENTrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/VAR_ASSIGNMENT.); |
| 4411 | let makefile = |
| 4412 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse variable assignment"); |
| 4413 | |
| 4414 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4415 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4416 | |
| 4417 | 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().(), 1, "Expected 1 variable, found {}", vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 4418 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0, "Expected 0 rules, found {}", rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 4419 | |
| 4420 | 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#("VARIABLE".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 4421 | |
| 4422 | // Test case: Simple rule with colon |
| 4423 | const SIMPLE_RULErust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/SIMPLE_RULE.: &str = "target: dependency\n"; |
| 4424 | |
| 4425 | let mut buf = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(SIMPLE_RULErust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/SIMPLE_RULE.); |
| 4426 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse simple rule"); |
| 4427 | |
| 4428 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4429 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4430 | |
| 4431 | 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().(), 0, "Expected 0 variables, found {}", vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 4432 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1, "Expected 1 rule, found {}", rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 4433 | |
| 4434 | let rule = &rules[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().; |
| 4435 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["target"]); |
| 4436 | } |
| 4437 | |
| 4438 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4439 | fn test_nested_conditionalsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_nested_conditionals().() { |
| 4440 | let content = r#" |
| 4441 | ifdef RELEASE |
| 4442 | CFLAGS += -O3 |
| 4443 | ifndef DEBUG |
| 4444 | ifneq ($(ARCH),arm) |
| 4445 | CFLAGS += -march=native |
| 4446 | else |
| 4447 | CFLAGS += -mcpu=cortex-a72 |
| 4448 | endif |
| 4449 | endif |
| 4450 | endif |
| 4451 | "#; |
| 4452 | // Use relaxed parsing for nested conditionals test |
| 4453 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4454 | let makefile = |
| 4455 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse nested conditionals"); |
| 4456 | |
| 4457 | // Check that we detected conditionals |
| 4458 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 4459 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef RELEASE")); |
| 4460 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifndef DEBUG")); |
| 4461 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifneq")); |
| 4462 | } |
| 4463 | |
| 4464 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4465 | fn test_space_indented_recipesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_space_indented_recipes().() { |
| 4466 | // This test is expected to fail with current implementation |
| 4467 | // It should pass once the parser is more flexible with indentation |
| 4468 | let content = r#" |
| 4469 | build: |
| 4470 | @echo "Building with spaces instead of tabs" |
| 4471 | gcc -o program main.c |
| 4472 | "#; |
| 4473 | // Use relaxed parsing for now |
| 4474 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4475 | let makefile = |
| 4476 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse space-indented recipes"); |
| 4477 | |
| 4478 | // Check that we can extract rules even with errors |
| 4479 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4480 | 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().rules.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Expected at least one rule"); |
| 4481 | |
| 4482 | // Find build rule |
| 4483 | let build_rule = rules.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."build")); |
| 4484 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(build_rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), "Expected to find build rule"); |
| 4485 | } |
| 4486 | |
| 4487 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4488 | fn test_complex_variable_functionsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_complex_variable_functions().() { |
| 4489 | let content = r#" |
| 4490 | FILES := $(shell find . -name "*.c") |
| 4491 | OBJS := $(patsubst %.c,%.o,$(FILES)) |
| 4492 | NAME := $(if $(PROGRAM),$(PROGRAM),a.out) |
| 4493 | HEADERS := ${wildcard *.h} |
| 4494 | "#; |
| 4495 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(content, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4496 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4497 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4498 | "Failed to parse complex variable functions: {:?}", |
| 4499 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors. |
| 4500 | ); |
| 4501 | } |
| 4502 | |
| 4503 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4504 | fn test_nested_variable_expansionsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_nested_variable_expansions().() { |
| 4505 | let content = r#" |
| 4506 | VERSION = 1.0 |
| 4507 | PACKAGE = myapp |
| 4508 | TARBALL = $(PACKAGE)-$(VERSION).tar.gz |
| 4509 | INSTALL_PATH = $(shell echo $(PREFIX) | sed 's/\/$//') |
| 4510 | "#; |
| 4511 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(content, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4512 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4513 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4514 | "Failed to parse nested variable expansions: {:?}", |
| 4515 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors. |
| 4516 | ); |
| 4517 | } |
| 4518 | |
| 4519 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4520 | fn test_special_directivesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_special_directives().() { |
| 4521 | let content = r#" |
| 4522 | # Special makefile directives |
| 4523 | .PHONY: all clean |
| 4524 | .SUFFIXES: .c .o |
| 4525 | .DEFAULT: all |
| 4526 | |
| 4527 | # Variable definition and export directive |
| 4528 | export PATH := /usr/bin:/bin |
| 4529 | "#; |
| 4530 | // Use relaxed parsing to allow for special directives |
| 4531 | let mut buf = content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 4532 | let makefile = |
| 4533 | Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut buf).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to parse special directives"); |
| 4534 | |
| 4535 | // Check that we can extract rules even with errors |
| 4536 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4537 | |
| 4538 | // Find phony rule |
| 4539 | let phony_rule = rules |
| 4540 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 4541 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(".PHONY"))); |
| 4542 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(phony_rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().(), "Expected to find .PHONY rule"); |
| 4543 | |
| 4544 | // Check that variables can be extracted |
| 4545 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4546 | 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.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Expected to find at least one variable"); |
| 4547 | } |
| 4548 | |
| 4549 | // Comprehensive Test combining multiple issues |
| 4550 | |
| 4551 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4552 | fn test_comprehensive_real_world_makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_comprehensive_real_world_makefile().() { |
| 4553 | // Simple makefile with basic elements |
| 4554 | let content = r#" |
| 4555 | # Basic variable assignment |
| 4556 | VERSION = 1.0.0 |
| 4557 | |
| 4558 | # Phony target |
| 4559 | .PHONY: all clean |
| 4560 | |
| 4561 | # Simple rule |
| 4562 | all: |
| 4563 | echo "Building version $(VERSION)" |
| 4564 | |
| 4565 | # Another rule with dependencies |
| 4566 | clean: |
| 4567 | rm -f *.o |
| 4568 | "#; |
| 4569 | |
| 4570 | // Parse the content |
| 4571 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(content, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4572 | |
| 4573 | // Check that parsing succeeded |
| 4574 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Expected no parsing errors"); |
| 4575 | |
| 4576 | // Check that we found variables |
| 4577 | let variables = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().().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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4578 | 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().variables.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Expected at least one variable"); |
| 4579 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 4580 | variables[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().(), |
| 4581 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("VERSION".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 4582 | "Expected VERSION variable" |
| 4583 | ); |
| 4584 | |
| 4585 | // Check that we found rules |
| 4586 | let rules = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().().rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4587 | 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().rules.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Expected at least one rule"); |
| 4588 | |
| 4589 | // Check for specific rules |
| 4590 | let rule_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = rules |
| 4591 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 4592 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 4593 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4594 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4595 | rule_targets.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&".PHONY".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 4596 | "Expected .PHONY rule" |
| 4597 | ); |
| 4598 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4599 | rule_targets.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"all".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 4600 | "Expected 'all' rule" |
| 4601 | ); |
| 4602 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4603 | rule_targets.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"clean".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 4604 | "Expected 'clean' rule" |
| 4605 | ); |
| 4606 | } |
| 4607 | |
| 4608 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4609 | fn test_indented_help_text_outside_rulesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_indented_help_text_outside_rules().() { |
| 4610 | // Create test content with indented help text |
| 4611 | let content = r#" |
| 4612 | # Targets with help text |
| 4613 | help: |
| 4614 | @echo "Available targets:" |
| 4615 | @echo " build build the project" |
| 4616 | @echo " test run tests" |
| 4617 | @echo " clean clean build artifacts" |
| 4618 | |
| 4619 | # Another target |
| 4620 | clean: |
| 4621 | rm -rf build/ |
| 4622 | "#; |
| 4623 | |
| 4624 | // Parse the content |
| 4625 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(content, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4626 | |
| 4627 | // Verify parsing succeeded |
| 4628 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4629 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4630 | "Failed to parse indented help text" |
| 4631 | ); |
| 4632 | |
| 4633 | // Check that we found the expected rules |
| 4634 | let rules = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().().rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4635 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2, "Expected to find two rules"); |
| 4636 | |
| 4637 | // Find the rules by target |
| 4638 | let help_rule = rules |
| 4639 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 4640 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."help")) |
| 4641 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Expected to find help rule"); |
| 4642 | |
| 4643 | let clean_rule = rules |
| 4644 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 4645 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."clean")) |
| 4646 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Expected to find clean rule"); |
| 4647 | |
| 4648 | // Check help rule has expected recipe lines |
| 4649 | let help_recipes = help_rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4650 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4651 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().help_recipes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4652 | "Help rule should have recipe lines" |
| 4653 | ); |
| 4654 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4655 | help_recipes |
| 4656 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 4657 | .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|line| line.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Available targets")), |
| 4658 | "Help recipes should include 'Available targets' line" |
| 4659 | ); |
| 4660 | |
| 4661 | // Check clean rule has expected recipe |
| 4662 | let clean_recipes = clean_rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4663 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4664 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().clean_recipes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4665 | "Clean rule should have recipe lines" |
| 4666 | ); |
| 4667 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4668 | clean_recipes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|line| line.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("rm -rf")), |
| 4669 | "Clean recipes should include 'rm -rf' command" |
| 4670 | ); |
| 4671 | } |
| 4672 | |
| 4673 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4674 | fn test_makefile1_phony_patternrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile1_phony_pattern().() { |
| 4675 | // Replicate the specific pattern in Makefile_1 that caused issues |
| 4676 | let content = "#line 2145\n.PHONY: $(PHONY)\n"; |
| 4677 | |
| 4678 | // Parse the content |
| 4679 | let result = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(content, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4680 | |
| 4681 | // Verify no parsing errors |
| 4682 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 4683 | result.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 4684 | "Failed to parse .PHONY: $(PHONY) pattern" |
| 4685 | ); |
| 4686 | |
| 4687 | // Check that the rule was parsed correctly |
| 4688 | let rules = result.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().().rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4689 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1, "Expected 1 rule"); |
| 4690 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 4691 | rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 4692 | ".PHONY", |
| 4693 | "Expected .PHONY rule" |
| 4694 | ); |
| 4695 | |
| 4696 | // Check that the prerequisite contains the variable reference |
| 4697 | let prereqs = rules[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()..prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4698 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(prereqs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1, "Expected 1 prerequisite"); |
| 4699 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(prereqs[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()., "$(PHONY)", "Expected $(PHONY) prerequisite"); |
| 4700 | } |
| 4701 | |
| 4702 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4703 | fn test_skip_until_newline_behaviorrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_skip_until_newline_behavior().() { |
| 4704 | // Test the skip_until_newline function to cover the != vs == mutant |
| 4705 | let input = "text without newline"; |
| 4706 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4707 | // This should handle gracefully without infinite loops |
| 4708 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4709 | |
| 4710 | let input_with_newline = "text\nafter newline"; |
| 4711 | let parsed2 = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input_with_newline, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4712 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed2.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parsed2.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4713 | } |
| 4714 | |
| 4715 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4716 | #[ignore] // Ignored until proper handling of orphaned indented lines is implemented |
| 4717 | fn test_error_with_indent_tokenrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_error_with_indent_token().() { |
| 4718 | // Test the error logic with INDENT token to cover the ! deletion mutant |
| 4719 | let input = "\tinvalid indented line"; |
| 4720 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4721 | // Should produce an error about indented line not part of a rule |
| 4722 | 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().parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4723 | |
| 4724 | let error_msg = &parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.[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()..messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.; |
| 4725 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(error_msg.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("recipe commences before first target")); |
| 4726 | } |
| 4727 | |
| 4728 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4729 | fn test_conditional_token_handlingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_token_handling().() { |
| 4730 | // Test conditional token handling to cover the == vs != mutant |
| 4731 | let input = r#" |
| 4732 | ifndef VAR |
| 4733 | CFLAGS = -DTEST |
| 4734 | endif |
| 4735 | "#; |
| 4736 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4737 | // Test that parsing doesn't panic and produces some result |
| 4738 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4739 | let _vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4740 | // Should handle conditionals, possibly with errors but without crashing |
| 4741 | |
| 4742 | // Test with nested conditionals |
| 4743 | let nested = r#" |
| 4744 | ifdef DEBUG |
| 4745 | ifndef RELEASE |
| 4746 | CFLAGS = -g |
| 4747 | endif |
| 4748 | endif |
| 4749 | "#; |
| 4750 | let parsed_nested = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(nested, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4751 | // Test that parsing doesn't panic |
| 4752 | let _makefile = parsed_nested.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4753 | } |
| 4754 | |
| 4755 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4756 | fn test_include_vs_conditional_logicrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_include_vs_conditional_logic().() { |
| 4757 | // Test the include vs conditional logic to cover the == vs != mutant at line 743 |
| 4758 | let input = r#" |
| 4759 | include file.mk |
| 4760 | ifdef VAR |
| 4761 | VALUE = 1 |
| 4762 | endif |
| 4763 | "#; |
| 4764 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4765 | // Test that parsing doesn't panic and produces some result |
| 4766 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4767 | let includes = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4768 | // Should recognize include directive |
| 4769 | 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().includes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4770 | |
| 4771 | // Test with -include |
| 4772 | let optional_include = r#" |
| 4773 | -include optional.mk |
| 4774 | ifndef VAR |
| 4775 | VALUE = default |
| 4776 | endif |
| 4777 | "#; |
| 4778 | let parsed2 = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(optional_include, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4779 | // Test that parsing doesn't panic |
| 4780 | let _makefile = parsed2.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4781 | } |
| 4782 | |
| 4783 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4784 | fn test_balanced_parens_countingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_balanced_parens_counting().() { |
| 4785 | // Test balanced parentheses parsing to cover the += vs -= mutant |
| 4786 | let input = r#" |
| 4787 | VAR = $(call func,$(nested,arg),extra) |
| 4788 | COMPLEX = $(if $(condition),$(then_val),$(else_val)) |
| 4789 | "#; |
| 4790 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4791 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4792 | |
| 4793 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4794 | let vars = 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().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4795 | 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); |
| 4796 | } |
| 4797 | |
| 4798 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4799 | fn test_documentation_lookaheadrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_documentation_lookahead().() { |
| 4800 | // Test the documentation lookahead logic to cover the - vs + mutant at line 895 |
| 4801 | let input = r#" |
| 4802 | # Documentation comment |
| 4803 | help: |
| 4804 | @echo "Usage instructions" |
| 4805 | @echo "More help text" |
| 4806 | "#; |
| 4807 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4808 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4809 | |
| 4810 | let makefile = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4811 | let rules = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 4812 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 4813 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "help"); |
| 4814 | } |
| 4815 | |
| 4816 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4817 | fn test_edge_case_empty_inputrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_edge_case_empty_input().() { |
| 4818 | // Test with empty input |
| 4819 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().("", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4820 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4821 | |
| 4822 | // Test with only whitespace |
| 4823 | let parsed2 = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(" \n \n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4824 | // Some parsers might report warnings/errors for whitespace-only input |
| 4825 | // Just ensure it doesn't crash |
| 4826 | let _makefile = parsed2.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 4827 | } |
| 4828 | |
| 4829 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4830 | fn test_malformed_conditional_recoveryrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_malformed_conditional_recovery().() { |
| 4831 | // Test parser recovery from malformed conditionals |
| 4832 | let input = r#" |
| 4833 | ifdef |
| 4834 | # Missing condition variable |
| 4835 | endif |
| 4836 | "#; |
| 4837 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 4838 | // Parser should either handle gracefully or report appropriate errors |
| 4839 | // Not checking for specific error since parsing strategy may vary |
| 4840 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 4841 | } |
| 4842 | |
| 4843 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4844 | fn test_replace_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_replace_rule().() { |
| 4845 | 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().(); |
| 4846 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "new_rule:\n\tnew_command\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().(); |
| 4847 | |
| 4848 | makefile.replace_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]replace_rule().(0, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4849 | |
| 4850 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile |
| 4851 | .rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().() |
| 4852 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 4853 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4854 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_rule", "rule2"]); |
| 4855 | |
| 4856 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().().recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4857 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_command"]); |
| 4858 | } |
| 4859 | |
| 4860 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4861 | fn test_replace_rule_out_of_boundsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_replace_rule_out_of_bounds().() { |
| 4862 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\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().(); |
| 4863 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "new_rule:\n\tnew_command\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().(); |
| 4864 | |
| 4865 | let result = makefile.replace_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]replace_rule().(5, new_rule); |
| 4866 | 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().()); |
| 4867 | } |
| 4868 | |
| 4869 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4870 | fn test_remove_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_remove_rule().() { |
| 4871 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\nrule2:\n\tcommand2\nrule3:\n\tcommand3\n" |
| 4872 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 4873 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4874 | |
| 4875 | let removed = makefile.remove_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_rule().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4876 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(removed.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule2"]); |
| 4877 | |
| 4878 | let remaining_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile |
| 4879 | .rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().() |
| 4880 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 4881 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4882 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(remaining_targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule1", "rule3"]); |
| 4883 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2); |
| 4884 | } |
| 4885 | |
| 4886 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4887 | fn test_remove_rule_out_of_boundsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_remove_rule_out_of_bounds().() { |
| 4888 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\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().(); |
| 4889 | |
| 4890 | let result = makefile.remove_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_rule().(5); |
| 4891 | 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().()); |
| 4892 | } |
| 4893 | |
| 4894 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4895 | fn test_insert_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_insert_rule().() { |
| 4896 | 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().(); |
| 4897 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "inserted_rule:\n\tinserted_command\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().(); |
| 4898 | |
| 4899 | makefile.insert_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_rule().(1, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4900 | |
| 4901 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile |
| 4902 | .rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().() |
| 4903 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 4904 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4905 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule1", "inserted_rule", "rule2"]); |
| 4906 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 3); |
| 4907 | } |
| 4908 | |
| 4909 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4910 | fn test_insert_rule_at_endrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_insert_rule_at_end().() { |
| 4911 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\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().(); |
| 4912 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "end_rule:\n\tend_command\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().(); |
| 4913 | |
| 4914 | makefile.insert_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_rule().(1, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4915 | |
| 4916 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile |
| 4917 | .rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().() |
| 4918 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 4919 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4920 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule1", "end_rule"]); |
| 4921 | } |
| 4922 | |
| 4923 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4924 | fn test_insert_rule_out_of_boundsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_insert_rule_out_of_bounds().() { |
| 4925 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\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().(); |
| 4926 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "new_rule:\n\tnew_command\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().(); |
| 4927 | |
| 4928 | let result = makefile.insert_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_rule().(5, new_rule); |
| 4929 | 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().()); |
| 4930 | } |
| 4931 | |
| 4932 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4933 | fn test_insert_rule_preserves_blank_line_spacing_at_endrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_insert_rule_preserves_blank_line_spacing_at_end().() { |
| 4934 | // Test that inserting at the end preserves blank line spacing |
| 4935 | let input = "rule1:\n\tcommand1\n\nrule2:\n\tcommand2\n"; |
| 4936 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.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().(); |
| 4937 | let new_rule = Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#::newrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]new().(&["rule3"], &[], &["command3"]); |
| 4938 | |
| 4939 | makefile.insert_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_rule().(2, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4940 | |
| 4941 | let expected = "rule1:\n\tcommand1\n\nrule2:\n\tcommand2\n\nrule3:\n\tcommand3\n"; |
| 4942 | 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().(), expected); |
| 4943 | } |
| 4944 | |
| 4945 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4946 | fn test_insert_rule_adds_blank_lines_when_missingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_insert_rule_adds_blank_lines_when_missing().() { |
| 4947 | // Test that inserting adds blank lines even when input has none |
| 4948 | let input = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n"; |
| 4949 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.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().(); |
| 4950 | let new_rule = Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#::newrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]new().(&["rule3"], &[], &["command3"]); |
| 4951 | |
| 4952 | makefile.insert_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_rule().(2, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4953 | |
| 4954 | let expected = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n\nrule3:\n\tcommand3\n"; |
| 4955 | 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().(), expected); |
| 4956 | } |
| 4957 | |
| 4958 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4959 | fn test_remove_commandrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_remove_command().() { |
| 4960 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\n\tcommand1\n\tcommand2\n\tcommand3\n" |
| 4961 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 4962 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 4963 | |
| 4964 | rule.remove_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_command().(1); |
| 4965 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4966 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command1", "command3"]); |
| 4967 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 2); |
| 4968 | } |
| 4969 | |
| 4970 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4971 | fn test_remove_command_out_of_boundsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_remove_command_out_of_bounds().() { |
| 4972 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\n\tcommand1\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().(); |
| 4973 | |
| 4974 | let result = rule.remove_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_command().(5); |
| 4975 | 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().result); |
| 4976 | } |
| 4977 | |
| 4978 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4979 | fn test_insert_commandrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_insert_command().() { |
| 4980 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\n\tcommand1\n\tcommand3\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().(); |
| 4981 | |
| 4982 | rule.insert_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]insert_command().(1, "command2"); |
| 4983 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4984 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command1", "command2", "command3"]); |
| 4985 | } |
| 4986 | |
| 4987 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4988 | fn test_insert_command_at_endrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_insert_command_at_end().() { |
| 4989 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\n\tcommand1\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().(); |
| 4990 | |
| 4991 | rule.insert_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]insert_command().(1, "command2"); |
| 4992 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 4993 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command1", "command2"]); |
| 4994 | } |
| 4995 | |
| 4996 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 4997 | fn test_insert_command_in_empty_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_insert_command_in_empty_rule().() { |
| 4998 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\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().(); |
| 4999 | |
| 5000 | rule.insert_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]insert_command().(0, "new_command"); |
| 5001 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5002 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_command"]); |
| 5003 | } |
| 5004 | |
| 5005 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5006 | fn test_recipe_countrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_count().() { |
| 5007 | let rule1: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\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().(); |
| 5008 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule1.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 0); |
| 5009 | |
| 5010 | let rule2: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\n\tcommand1\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().(); |
| 5011 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule2.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 2); |
| 5012 | } |
| 5013 | |
| 5014 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5015 | fn test_clear_commandsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_clear_commands().() { |
| 5016 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\n\tcommand1\n\tcommand2\n\tcommand3\n" |
| 5017 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5018 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5019 | |
| 5020 | rule.clear_commandsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]clear_commands().(); |
| 5021 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 0); |
| 5022 | |
| 5023 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5024 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()); |
| 5025 | |
| 5026 | // Rule target should still be preserved |
| 5027 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5028 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 5029 | } |
| 5030 | |
| 5031 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5032 | fn test_clear_commands_empty_rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_clear_commands_empty_rule().() { |
| 5033 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\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().(); |
| 5034 | |
| 5035 | rule.clear_commandsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]clear_commands().(); |
| 5036 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 0); |
| 5037 | |
| 5038 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5039 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 5040 | } |
| 5041 | |
| 5042 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5043 | fn test_rule_manipulation_preserves_structurerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_manipulation_preserves_structure().() { |
| 5044 | // Test that makefile structure (comments, variables, etc.) is preserved during rule manipulation |
| 5045 | let input = r#"# Comment |
| 5046 | VAR = value |
| 5047 | |
| 5048 | rule1: |
| 5049 | command1 |
| 5050 | |
| 5051 | # Another comment |
| 5052 | rule2: |
| 5053 | command2 |
| 5054 | |
| 5055 | VAR2 = value2 |
| 5056 | "#; |
| 5057 | |
| 5058 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.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().(); |
| 5059 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "new_rule:\n\tnew_command\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().(); |
| 5060 | |
| 5061 | // Insert rule in the middle |
| 5062 | makefile.insert_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_rule().(1, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5063 | |
| 5064 | // Check that rules are correct |
| 5065 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile |
| 5066 | .rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().() |
| 5067 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 5068 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5069 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule1", "new_rule", "rule2"]); |
| 5070 | |
| 5071 | // Check that variables are preserved |
| 5072 | 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().(); |
| 5073 | 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); |
| 5074 | |
| 5075 | // The structure should be preserved in the output |
| 5076 | let output = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 5077 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("# Comment")); |
| 5078 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = value")); |
| 5079 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("# Another comment")); |
| 5080 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR2 = value2")); |
| 5081 | } |
| 5082 | |
| 5083 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5084 | fn test_replace_rule_with_multiple_targetsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_replace_rule_with_multiple_targets().() { |
| 5085 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "target1 target2: dep\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().(); |
| 5086 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "new_target: new_dep\n\tnew_command\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().(); |
| 5087 | |
| 5088 | makefile.replace_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]replace_rule().(0, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5089 | |
| 5090 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile |
| 5091 | .rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().() |
| 5092 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 5093 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5094 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_target"]); |
| 5095 | } |
| 5096 | |
| 5097 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5098 | fn test_empty_makefile_operationsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_empty_makefile_operations().() { |
| 5099 | 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().(); |
| 5100 | |
| 5101 | // Test operations on empty makefile |
| 5102 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile |
| 5103 | .replace_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]replace_rule().(0, "rule:\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().()) |
| 5104 | .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 5105 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.remove_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_rule().(0).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 5106 | |
| 5107 | // Insert into empty makefile should work |
| 5108 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "first_rule:\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().(); |
| 5109 | makefile.insert_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_rule().(0, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5110 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 5111 | } |
| 5112 | |
| 5113 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5114 | fn test_command_operations_preserve_indentationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_command_operations_preserve_indentation().() { |
| 5115 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "rule:\n\t\tdeep_indent\n\tshallow_indent\n" |
| 5116 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5117 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5118 | |
| 5119 | rule.insert_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]insert_command().(1, "middle_command"); |
| 5120 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5121 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5122 | recipes, |
| 5123 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["\tdeep_indent", "middle_command", "shallow_indent"] |
| 5124 | ); |
| 5125 | } |
| 5126 | |
| 5127 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5128 | fn test_rule_operations_with_variables_and_includesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_operations_with_variables_and_includes().() { |
| 5129 | let input = r#"VAR1 = value1 |
| 5130 | include common.mk |
| 5131 | |
| 5132 | rule1: |
| 5133 | command1 |
| 5134 | |
| 5135 | VAR2 = value2 |
| 5136 | include other.mk |
| 5137 | |
| 5138 | rule2: |
| 5139 | command2 |
| 5140 | "#; |
| 5141 | |
| 5142 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.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().(); |
| 5143 | |
| 5144 | // Remove middle rule |
| 5145 | makefile.remove_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_rule().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5146 | |
| 5147 | // Verify structure is preserved |
| 5148 | let output = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 5149 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR1 = value1")); |
| 5150 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("include common.mk")); |
| 5151 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR2 = value2")); |
| 5152 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("include other.mk")); |
| 5153 | |
| 5154 | // Only rule2 should remain |
| 5155 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 5156 | let remaining_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile |
| 5157 | .rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().() |
| 5158 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()) |
| 5159 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5160 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(remaining_targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule2"]); |
| 5161 | } |
| 5162 | |
| 5163 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5164 | fn test_command_manipulation_edge_casesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_command_manipulation_edge_cases().() { |
| 5165 | // Test with rule that has no commands |
| 5166 | let mut empty_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "empty:\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().(); |
| 5167 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(empty_rule.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 0); |
| 5168 | |
| 5169 | empty_rule.insert_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]insert_command().(0, "first_command"); |
| 5170 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(empty_rule.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 1); |
| 5171 | |
| 5172 | // Test clearing already empty rule |
| 5173 | let mut empty_rule2: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "empty:\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().(); |
| 5174 | empty_rule2.clear_commandsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]clear_commands().(); |
| 5175 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(empty_rule2.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 0); |
| 5176 | } |
| 5177 | |
| 5178 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5179 | fn test_large_makefile_performancerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_large_makefile_performance().() { |
| 5180 | // Create a makefile with many rules to test performance doesn't degrade |
| 5181 | 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().(); |
| 5182 | |
| 5183 | // Add 100 rules |
| 5184 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#100 { |
| 5185 | let rule_name = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("rule{}", i); |
| 5186 | makefile |
| 5187 | .add_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_rule().(&rule_name) |
| 5188 | .push_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]push_command().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("command{}", i)); |
| 5189 | } |
| 5190 | |
| 5191 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 100); |
| 5192 | |
| 5193 | // Replace rule in the middle - should be efficient |
| 5194 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "middle_rule:\n\tmiddle_command\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().(); |
| 5195 | makefile.replace_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]replace_rule().(50, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5196 | |
| 5197 | // Verify the change |
| 5198 | let rule_50_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(50).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5199 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule_50_targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["middle_rule"]); |
| 5200 | |
| 5201 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 100); // Count unchanged |
| 5202 | } |
| 5203 | |
| 5204 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5205 | fn test_complex_recipe_manipulationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_complex_recipe_manipulation().() { |
| 5206 | let mut complex_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = r#"complex: |
| 5207 | @echo "Starting build" |
| 5208 | $(CC) $(CFLAGS) -o $@ $< |
| 5209 | @echo "Build complete" |
| 5210 | chmod +x $@ |
| 5211 | "# |
| 5212 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5213 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5214 | |
| 5215 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(complex_rule.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 4); |
| 5216 | |
| 5217 | // Remove the echo statements, keep the actual build commands |
| 5218 | complex_rule.remove_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_command().(0); // Remove first echo |
| 5219 | complex_rule.remove_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_command().(1); // Remove second echo (now at index 1, not 2) |
| 5220 | |
| 5221 | let final_recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = complex_rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5222 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(final_recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 5223 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(final_recipes[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()..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("$(CC)")); |
| 5224 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(final_recipes[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()..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("chmod")); |
| 5225 | } |
| 5226 | |
| 5227 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5228 | fn test_variable_definition_removerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_definition_remove().() { |
| 5229 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5230 | VAR2 = value2 |
| 5231 | VAR3 = value3 |
| 5232 | "# |
| 5233 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5234 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5235 | |
| 5236 | // Verify we have 3 variables |
| 5237 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 3); |
| 5238 | |
| 5239 | // Remove the second variable |
| 5240 | let mut var2 = makefile |
| 5241 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5242 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1) |
| 5243 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have second variable"); |
| 5244 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var2.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#("VAR2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5245 | var2.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5246 | |
| 5247 | // Verify we now have 2 variables and VAR2 is gone |
| 5248 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2); |
| 5249 | let var_names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile |
| 5250 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5251 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|v| v.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().()) |
| 5252 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5253 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var_names, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["VAR1", "VAR3"]); |
| 5254 | } |
| 5255 | |
| 5256 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5257 | fn test_variable_definition_set_valuerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_definition_set_value().() { |
| 5258 | 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().(); |
| 5259 | |
| 5260 | let mut var = makefile |
| 5261 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5262 | .nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().() |
| 5263 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have variable"); |
| 5264 | 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().())); |
| 5265 | |
| 5266 | // Change the value |
| 5267 | var.set_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_value().("new_value"); |
| 5268 | |
| 5269 | // Verify the value changed |
| 5270 | 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().())); |
| 5271 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = new_value")); |
| 5272 | } |
| 5273 | |
| 5274 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5275 | fn test_variable_definition_set_value_preserves_formatrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_definition_set_value_preserves_format().() { |
| 5276 | 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().(); |
| 5277 | |
| 5278 | let mut var = makefile |
| 5279 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5280 | .nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().() |
| 5281 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have variable"); |
| 5282 | 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().())); |
| 5283 | |
| 5284 | // Change the value |
| 5285 | var.set_valuerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]set_value().("new_value"); |
| 5286 | |
| 5287 | // Verify the value changed but format preserved |
| 5288 | 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().())); |
| 5289 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 5290 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("export"), "Should preserve export prefix"); |
| 5291 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(":="), "Should preserve := operator"); |
| 5292 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("new_value"), "Should have new value"); |
| 5293 | } |
| 5294 | |
| 5295 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5296 | fn test_makefile_find_variablerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_variable().() { |
| 5297 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5298 | VAR2 = value2 |
| 5299 | VAR3 = value3 |
| 5300 | "# |
| 5301 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5302 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5303 | |
| 5304 | // Find existing variable |
| 5305 | let vars: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("VAR2").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5306 | 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().(), 1); |
| 5307 | 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#("VAR2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5308 | 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()..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#("value2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5309 | |
| 5310 | // Try to find non-existent variable |
| 5311 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("NONEXISTENT").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(), 0); |
| 5312 | } |
| 5313 | |
| 5314 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5315 | fn test_makefile_find_variable_with_exportrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_variable_with_export().() { |
| 5316 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5317 | export VAR2 := value2 |
| 5318 | VAR3 = value3 |
| 5319 | "# |
| 5320 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5321 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5322 | |
| 5323 | // Find exported variable |
| 5324 | let vars: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("VAR2").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5325 | 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().(), 1); |
| 5326 | 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#("VAR2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5327 | 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()..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#("value2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5328 | } |
| 5329 | |
| 5330 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5331 | fn test_variable_definition_is_exportrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_definition_is_export().() { |
| 5332 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5333 | export VAR2 := value2 |
| 5334 | export VAR3 = value3 |
| 5335 | VAR4 := value4 |
| 5336 | "# |
| 5337 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5338 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5339 | |
| 5340 | 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().(); |
| 5341 | 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().(), 4); |
| 5342 | |
| 5343 | 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_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().()); |
| 5344 | 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_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().()); |
| 5345 | 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().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().()); |
| 5346 | 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().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_exportrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]is_export().()); |
| 5347 | } |
| 5348 | |
| 5349 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5350 | fn test_makefile_find_variable_multiplerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_variable_multiple().() { |
| 5351 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5352 | VAR1 = value2 |
| 5353 | VAR2 = other |
| 5354 | VAR1 = value3 |
| 5355 | "# |
| 5356 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5357 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5358 | |
| 5359 | // Find all VAR1 definitions |
| 5360 | let vars: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("VAR1").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5361 | 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().(), 3); |
| 5362 | 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()..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#("value1".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5363 | 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()..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#("value2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5364 | 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().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..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#("value3".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5365 | |
| 5366 | // Find VAR2 |
| 5367 | let var2s: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("VAR2").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5368 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var2s.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 5369 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var2s[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()..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#("other".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5370 | } |
| 5371 | |
| 5372 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5373 | fn test_variable_remove_and_findrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_remove_and_find().() { |
| 5374 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5375 | VAR2 = value2 |
| 5376 | VAR3 = value3 |
| 5377 | "# |
| 5378 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5379 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5380 | |
| 5381 | // Find and remove VAR2 |
| 5382 | let mut var2 = makefile |
| 5383 | .find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("VAR2") |
| 5384 | .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]next().() |
| 5385 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should find VAR2"); |
| 5386 | var2.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5387 | |
| 5388 | // Verify VAR2 is gone |
| 5389 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("VAR2").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(), 0); |
| 5390 | |
| 5391 | // Verify other variables still exist |
| 5392 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("VAR1").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(), 1); |
| 5393 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().("VAR3").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(), 1); |
| 5394 | } |
| 5395 | |
| 5396 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5397 | fn test_variable_remove_with_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_remove_with_comment().() { |
| 5398 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5399 | # This is a comment about VAR2 |
| 5400 | VAR2 = value2 |
| 5401 | VAR3 = value3 |
| 5402 | "# |
| 5403 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5404 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5405 | |
| 5406 | // Remove VAR2 |
| 5407 | let mut var2 = makefile |
| 5408 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5409 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1) |
| 5410 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have second variable"); |
| 5411 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(var2.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#("VAR2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5412 | var2.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5413 | |
| 5414 | // Verify the comment is also removed |
| 5415 | 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().(), "VAR1 = value1\nVAR3 = value3\n"); |
| 5416 | } |
| 5417 | |
| 5418 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5419 | fn test_variable_remove_with_multiple_commentsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_remove_with_multiple_comments().() { |
| 5420 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5421 | # Comment line 1 |
| 5422 | # Comment line 2 |
| 5423 | # Comment line 3 |
| 5424 | VAR2 = value2 |
| 5425 | VAR3 = value3 |
| 5426 | "# |
| 5427 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5428 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5429 | |
| 5430 | // Remove VAR2 |
| 5431 | let mut var2 = makefile |
| 5432 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5433 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1) |
| 5434 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have second variable"); |
| 5435 | var2.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5436 | |
| 5437 | // Verify all comments are removed |
| 5438 | 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().(), "VAR1 = value1\nVAR3 = value3\n"); |
| 5439 | } |
| 5440 | |
| 5441 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5442 | fn test_variable_remove_with_empty_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_remove_with_empty_line().() { |
| 5443 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5444 | |
| 5445 | # Comment about VAR2 |
| 5446 | VAR2 = value2 |
| 5447 | VAR3 = value3 |
| 5448 | "# |
| 5449 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5450 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5451 | |
| 5452 | // Remove VAR2 |
| 5453 | let mut var2 = makefile |
| 5454 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5455 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1) |
| 5456 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have second variable"); |
| 5457 | var2.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5458 | |
| 5459 | // Verify comment and up to 1 empty line are removed |
| 5460 | // Should have VAR1, then newline, then VAR3 (empty line removed) |
| 5461 | 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().(), "VAR1 = value1\nVAR3 = value3\n"); |
| 5462 | } |
| 5463 | |
| 5464 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5465 | fn test_variable_remove_with_multiple_empty_linesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_remove_with_multiple_empty_lines().() { |
| 5466 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5467 | |
| 5468 | |
| 5469 | # Comment about VAR2 |
| 5470 | VAR2 = value2 |
| 5471 | VAR3 = value3 |
| 5472 | "# |
| 5473 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5474 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5475 | |
| 5476 | // Remove VAR2 |
| 5477 | let mut var2 = makefile |
| 5478 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5479 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1) |
| 5480 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have second variable"); |
| 5481 | var2.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5482 | |
| 5483 | // Verify comment and only 1 empty line are removed (one empty line preserved) |
| 5484 | // Should preserve one empty line before where VAR2 was |
| 5485 | 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().(), "VAR1 = value1\n\nVAR3 = value3\n"); |
| 5486 | } |
| 5487 | |
| 5488 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5489 | fn test_rule_remove_with_commentrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_remove_with_comment().() { |
| 5490 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"rule1: |
| 5491 | command1 |
| 5492 | |
| 5493 | # Comment about rule2 |
| 5494 | rule2: |
| 5495 | command2 |
| 5496 | rule3: |
| 5497 | command3 |
| 5498 | "# |
| 5499 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5500 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5501 | |
| 5502 | // Remove rule2 |
| 5503 | let rule2 = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have second rule"); |
| 5504 | rule2.removerust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5505 | |
| 5506 | // Verify the comment is removed |
| 5507 | // Note: The empty line after rule1 is part of rule1's text, not a sibling, so it's preserved |
| 5508 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5509 | makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), |
| 5510 | "rule1:\n\tcommand1\n\nrule3:\n\tcommand3\n" |
| 5511 | ); |
| 5512 | } |
| 5513 | |
| 5514 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5515 | fn test_variable_remove_preserves_shebangrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_remove_preserves_shebang().() { |
| 5516 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"#!/usr/bin/make -f |
| 5517 | # This is a regular comment |
| 5518 | VAR1 = value1 |
| 5519 | VAR2 = value2 |
| 5520 | "# |
| 5521 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5522 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5523 | |
| 5524 | // Remove VAR1 |
| 5525 | let mut var1 = 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().(); |
| 5526 | var1.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5527 | |
| 5528 | // Verify the shebang is preserved but regular comment is removed |
| 5529 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 5530 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("#!/usr/bin/make -f")); |
| 5531 | 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().code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("regular comment")); |
| 5532 | 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().code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR1")); |
| 5533 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR2")); |
| 5534 | } |
| 5535 | |
| 5536 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5537 | fn test_variable_remove_preserves_subsequent_commentsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_remove_preserves_subsequent_comments().() { |
| 5538 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 5539 | # Comment about VAR2 |
| 5540 | VAR2 = value2 |
| 5541 | |
| 5542 | # Comment about VAR3 |
| 5543 | VAR3 = value3 |
| 5544 | "# |
| 5545 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5546 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5547 | |
| 5548 | // Remove VAR2 |
| 5549 | let mut var2 = makefile |
| 5550 | .variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().() |
| 5551 | .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1) |
| 5552 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have second variable"); |
| 5553 | var2.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5554 | |
| 5555 | // Verify preceding comment is removed but subsequent comment/empty line are preserved |
| 5556 | let code = makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(); |
| 5557 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5558 | code, |
| 5559 | "VAR1 = value1\n\n# Comment about VAR3\nVAR3 = value3\n" |
| 5560 | ); |
| 5561 | } |
| 5562 | |
| 5563 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5564 | fn test_variable_remove_after_shebang_preserves_empty_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_variable_remove_after_shebang_preserves_empty_line().() { |
| 5565 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"#!/usr/bin/make -f |
| 5566 | export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed |
| 5567 | |
| 5568 | %: |
| 5569 | dh $@ |
| 5570 | "# |
| 5571 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5572 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5573 | |
| 5574 | // Remove the variable |
| 5575 | 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().(); |
| 5576 | var.removerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]remove().(); |
| 5577 | |
| 5578 | // Verify shebang is preserved and empty line after variable is preserved |
| 5579 | 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().(), "#!/usr/bin/make -f\n\n%:\n\tdh $@\n"); |
| 5580 | } |
| 5581 | |
| 5582 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5583 | fn test_rule_add_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_add_prerequisite().() { |
| 5584 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target: dep1\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().(); |
| 5585 | rule.add_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_prerequisite().("dep2").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5586 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5587 | rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5588 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dep1", "dep2"] |
| 5589 | ); |
| 5590 | // Verify proper spacing |
| 5591 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "target: dep1 dep2\n"); |
| 5592 | } |
| 5593 | |
| 5594 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5595 | fn test_rule_add_prerequisite_to_rule_without_prereqsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_add_prerequisite_to_rule_without_prereqs().() { |
| 5596 | // Regression test for missing space after colon when adding first prerequisite |
| 5597 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target:\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().(); |
| 5598 | rule.add_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_prerequisite().("dep1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5599 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dep1"]); |
| 5600 | // Should have space after colon |
| 5601 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "target: dep1\n"); |
| 5602 | } |
| 5603 | |
| 5604 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5605 | fn test_rule_remove_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_remove_prerequisite().() { |
| 5606 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target: dep1 dep2 dep3\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().(); |
| 5607 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.remove_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_prerequisite().("dep2").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5608 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5609 | rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5610 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dep1", "dep3"] |
| 5611 | ); |
| 5612 | 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().rule.remove_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_prerequisite().("nonexistent").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5613 | } |
| 5614 | |
| 5615 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5616 | fn test_rule_set_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_set_prerequisites().() { |
| 5617 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target: old_dep\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().(); |
| 5618 | rule.set_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]set_prerequisites().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_dep1", "new_dep2"]) |
| 5619 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5620 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5621 | rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5622 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_dep1", "new_dep2"] |
| 5623 | ); |
| 5624 | } |
| 5625 | |
| 5626 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5627 | fn test_rule_set_prerequisites_emptyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_set_prerequisites_empty().() { |
| 5628 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target: dep1 dep2\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().(); |
| 5629 | rule.set_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]set_prerequisites().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5630 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0); |
| 5631 | } |
| 5632 | |
| 5633 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5634 | fn test_rule_add_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_add_target().() { |
| 5635 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target1: dep1\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().(); |
| 5636 | rule.add_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_target().("target2").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5637 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5638 | rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5639 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["target1", "target2"] |
| 5640 | ); |
| 5641 | } |
| 5642 | |
| 5643 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5644 | fn test_rule_set_targetsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_set_targets().() { |
| 5645 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "old_target: dependency\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().(); |
| 5646 | rule.set_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]set_targets().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_target1", "new_target2"]) |
| 5647 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5648 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5649 | rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5650 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_target1", "new_target2"] |
| 5651 | ); |
| 5652 | } |
| 5653 | |
| 5654 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5655 | fn test_rule_set_targets_emptyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_set_targets_empty().() { |
| 5656 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target: dep1\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().(); |
| 5657 | let result = rule.set_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]set_targets().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]); |
| 5658 | 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().()); |
| 5659 | // Verify target wasn't changed |
| 5660 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["target"]); |
| 5661 | } |
| 5662 | |
| 5663 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5664 | fn test_rule_has_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_has_target().() { |
| 5665 | let rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target1 target2: dependency\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().(); |
| 5666 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.has_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]has_target().("target1")); |
| 5667 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.has_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]has_target().("target2")); |
| 5668 | 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().rule.has_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]has_target().("target3")); |
| 5669 | 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().rule.has_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]has_target().("nonexistent")); |
| 5670 | } |
| 5671 | |
| 5672 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5673 | fn test_rule_rename_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_rename_target().() { |
| 5674 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "old_target: dependency\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().(); |
| 5675 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.rename_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]rename_target().("old_target", "new_target").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5676 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["new_target"]); |
| 5677 | // Try renaming non-existent target |
| 5678 | 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().rule.rename_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]rename_target().("nonexistent", "something").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5679 | } |
| 5680 | |
| 5681 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5682 | fn test_rule_rename_target_multiplerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_rename_target_multiple().() { |
| 5683 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target1 target2 target3: dependency\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().(); |
| 5684 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.rename_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]rename_target().("target2", "renamed_target").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5685 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5686 | rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5687 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["target1", "renamed_target", "target3"] |
| 5688 | ); |
| 5689 | } |
| 5690 | |
| 5691 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5692 | fn test_rule_remove_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_remove_target().() { |
| 5693 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target1 target2 target3: dependency\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().(); |
| 5694 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.remove_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_target().("target2").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5695 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5696 | rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5697 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["target1", "target3"] |
| 5698 | ); |
| 5699 | // Try removing non-existent target |
| 5700 | 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().rule.remove_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_target().("nonexistent").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5701 | } |
| 5702 | |
| 5703 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5704 | fn test_rule_remove_target_lastrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_remove_target_last().() { |
| 5705 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "single_target: dependency\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().(); |
| 5706 | let result = rule.remove_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_target().("single_target"); |
| 5707 | 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().()); |
| 5708 | // Verify target wasn't removed |
| 5709 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["single_target"]); |
| 5710 | } |
| 5711 | |
| 5712 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5713 | fn test_rule_target_manipulation_preserves_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_target_manipulation_preserves_prerequisites().() { |
| 5714 | let mut rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "target1 target2: dep1 dep2\n\tcommand".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().(); |
| 5715 | |
| 5716 | // Remove a target |
| 5717 | rule.remove_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_target().("target1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5718 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["target2"]); |
| 5719 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5720 | rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5721 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dep1", "dep2"] |
| 5722 | ); |
| 5723 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command"]); |
| 5724 | |
| 5725 | // Add a target |
| 5726 | rule.add_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_target().("target3").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5727 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5728 | rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5729 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["target2", "target3"] |
| 5730 | ); |
| 5731 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5732 | rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5733 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dep1", "dep2"] |
| 5734 | ); |
| 5735 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command"]); |
| 5736 | |
| 5737 | // Rename a target |
| 5738 | rule.rename_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]rename_target().("target2", "renamed").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5739 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5740 | rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5741 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["renamed", "target3"] |
| 5742 | ); |
| 5743 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 5744 | rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 5745 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dep1", "dep2"] |
| 5746 | ); |
| 5747 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["command"]); |
| 5748 | } |
| 5749 | |
| 5750 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5751 | fn test_rule_removerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_remove().() { |
| 5752 | let 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().(); |
| 5753 | let rule = makefile.find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().("rule1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 5754 | rule.removerust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5755 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 5756 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().("rule1").is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 5757 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().("rule2").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 5758 | } |
| 5759 | |
| 5760 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5761 | fn test_rule_remove_last_trims_blank_linesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_remove_last_trims_blank_lines().() { |
| 5762 | // Regression test for bug where removing the last rule left trailing blank lines |
| 5763 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = |
| 5764 | "%:\n\tdh $@\n\noverride_dh_missing:\n\tdh_missing --fail-missing\n" |
| 5765 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5766 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5767 | |
| 5768 | // Remove the last rule (override_dh_missing) |
| 5769 | let rule = makefile.find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().("override_dh_missing").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 5770 | rule.removerust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5771 | |
| 5772 | // Should not have trailing blank line |
| 5773 | 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().(), "%:\n\tdh $@\n"); |
| 5774 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 5775 | } |
| 5776 | |
| 5777 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5778 | fn test_makefile_find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rule_by_target().() { |
| 5779 | let 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().(); |
| 5780 | let rule = makefile.find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().("rule2"); |
| 5781 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 5782 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule2"]); |
| 5783 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().("nonexistent").is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 5784 | } |
| 5785 | |
| 5786 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5787 | fn test_makefile_find_rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rules_by_target().() { |
| 5788 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\nrule1:\n\tcommand2\nrule2:\n\tcommand3\n" |
| 5789 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5790 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5791 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.find_rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target().("rule1").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(), 2); |
| 5792 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.find_rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target().("rule2").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(), 1); |
| 5793 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.find_rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target().("nonexistent").countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().(), 0); |
| 5794 | } |
| 5795 | |
| 5796 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5797 | fn test_makefile_find_rule_by_target_pattern_simplerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rule_by_target_pattern_simple().() { |
| 5798 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "%.o: %.c\n\t$(CC) -c $<\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().(); |
| 5799 | let rule = makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("foo.o"); |
| 5800 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 5801 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "%.o"); |
| 5802 | } |
| 5803 | |
| 5804 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5805 | fn test_makefile_find_rule_by_target_pattern_no_matchrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rule_by_target_pattern_no_match().() { |
| 5806 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "%.o: %.c\n\t$(CC) -c $<\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().(); |
| 5807 | let rule = makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("foo.c"); |
| 5808 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 5809 | } |
| 5810 | |
| 5811 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5812 | fn test_makefile_find_rule_by_target_pattern_exactrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rule_by_target_pattern_exact().() { |
| 5813 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "foo.o: foo.c\n\t$(CC) -c $<\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().(); |
| 5814 | let rule = makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("foo.o"); |
| 5815 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 5816 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "foo.o"); |
| 5817 | } |
| 5818 | |
| 5819 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5820 | fn test_makefile_find_rule_by_target_pattern_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rule_by_target_pattern_prefix().() { |
| 5821 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "lib%.a: %.o\n\tar rcs $@ $<\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().(); |
| 5822 | let rule = makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("libfoo.a"); |
| 5823 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 5824 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "lib%.a"); |
| 5825 | } |
| 5826 | |
| 5827 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5828 | fn test_makefile_find_rule_by_target_pattern_suffixrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rule_by_target_pattern_suffix().() { |
| 5829 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "%_test.o: %.c\n\t$(CC) -c $<\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().(); |
| 5830 | let rule = makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("foo_test.o"); |
| 5831 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 5832 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "%_test.o"); |
| 5833 | } |
| 5834 | |
| 5835 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5836 | fn test_makefile_find_rule_by_target_pattern_middlerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rule_by_target_pattern_middle().() { |
| 5837 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "lib%_debug.a: %.o\n\tar rcs $@ $<\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().(); |
| 5838 | let rule = makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("libfoo_debug.a"); |
| 5839 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 5840 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "lib%_debug.a"); |
| 5841 | } |
| 5842 | |
| 5843 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5844 | fn test_makefile_find_rule_by_target_pattern_wildcard_onlyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rule_by_target_pattern_wildcard_only().() { |
| 5845 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "%: %.c\n\t$(CC) -o $@ $<\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().(); |
| 5846 | let rule = makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("anything"); |
| 5847 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(rule.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 5848 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "%"); |
| 5849 | } |
| 5850 | |
| 5851 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5852 | fn test_makefile_find_rules_by_target_pattern_multiplerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rules_by_target_pattern_multiple().() { |
| 5853 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "%.o: %.c\n\t$(CC) -c $<\n%.o: %.s\n\t$(AS) -o $@ $<\n" |
| 5854 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5855 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5856 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_rules_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target_pattern().("foo.o").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5857 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 5858 | } |
| 5859 | |
| 5860 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5861 | fn test_makefile_find_rules_by_target_pattern_mixedrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rules_by_target_pattern_mixed().() { |
| 5862 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = |
| 5863 | "%.o: %.c\n\t$(CC) -c $<\nfoo.o: foo.h\n\t$(CC) -c foo.c\nbar.txt: baz.txt\n\tcp $< $@\n" |
| 5864 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 5865 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5866 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_rules_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target_pattern().("foo.o").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5867 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); // Matches both %.o and foo.o |
| 5868 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_rules_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target_pattern().("bar.txt").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5869 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); // Only exact match |
| 5870 | } |
| 5871 | |
| 5872 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5873 | fn test_makefile_find_rules_by_target_pattern_no_wildcardrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_find_rules_by_target_pattern_no_wildcard().() { |
| 5874 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "foo.o: foo.c\n\t$(CC) -c $<\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().(); |
| 5875 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_rules_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target_pattern().("foo.o").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5876 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 5877 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.find_rules_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target_pattern().("bar.o").collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5878 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0); |
| 5879 | } |
| 5880 | |
| 5881 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5882 | fn test_matches_pattern_exactrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_matches_pattern_exact().() { |
| 5883 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("foo.o", "foo.o")); |
| 5884 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("foo.o", "bar.o")); |
| 5885 | } |
| 5886 | |
| 5887 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5888 | fn test_matches_pattern_suffixrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_matches_pattern_suffix().() { |
| 5889 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%.o", "foo.o")); |
| 5890 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%.o", "bar.o")); |
| 5891 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%.o", "baz/qux.o")); |
| 5892 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%.o", "foo.c")); |
| 5893 | } |
| 5894 | |
| 5895 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5896 | fn test_matches_pattern_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_matches_pattern_prefix().() { |
| 5897 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%.a", "libfoo.a")); |
| 5898 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%.a", "libbar.a")); |
| 5899 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%.a", "foo.a")); |
| 5900 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%.a", "lib.a")); |
| 5901 | } |
| 5902 | |
| 5903 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5904 | fn test_matches_pattern_middlerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_matches_pattern_middle().() { |
| 5905 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%_debug.a", "libfoo_debug.a")); |
| 5906 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%_debug.a", "libbar_debug.a")); |
| 5907 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%_debug.a", "libfoo.a")); |
| 5908 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%_debug.a", "foo_debug.a")); |
| 5909 | } |
| 5910 | |
| 5911 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5912 | fn test_matches_pattern_wildcard_onlyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_matches_pattern_wildcard_only().() { |
| 5913 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%", "anything")); |
| 5914 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%", "foo.o")); |
| 5915 | // GNU make: stem must be non-empty, so "%" does NOT match "" |
| 5916 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%", "")); |
| 5917 | } |
| 5918 | |
| 5919 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5920 | fn test_matches_pattern_empty_stemrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_matches_pattern_empty_stem().() { |
| 5921 | // GNU make: stem must be non-empty |
| 5922 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%.o", ".o")); // stem would be empty |
| 5923 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%", "lib")); // stem would be empty |
| 5924 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%.a", "lib.a")); // stem would be empty |
| 5925 | } |
| 5926 | |
| 5927 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5928 | fn test_matches_pattern_multiple_wildcards_not_supportedrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_matches_pattern_multiple_wildcards_not_supported().() { |
| 5929 | // GNU make does NOT support multiple % in pattern rules |
| 5930 | // These should not match (fall back to exact match) |
| 5931 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("%foo%bar", "xfooybarz")); |
| 5932 | 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().matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().("lib%.so.%", "libfoo.so.1")); |
| 5933 | } |
| 5934 | |
| 5935 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5936 | fn test_makefile_add_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_add_phony_target().() { |
| 5937 | 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().(); |
| 5938 | makefile.add_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_phony_target().("clean").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5939 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("clean")); |
| 5940 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.phony_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]phony_targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["clean"]); |
| 5941 | } |
| 5942 | |
| 5943 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5944 | fn test_makefile_add_phony_target_existingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_add_phony_target_existing().() { |
| 5945 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = ".PHONY: test\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().(); |
| 5946 | makefile.add_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_phony_target().("clean").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 5947 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("test")); |
| 5948 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("clean")); |
| 5949 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.phony_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]phony_targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5950 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(targets.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5951 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(targets.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"clean".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 5952 | } |
| 5953 | |
| 5954 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5955 | fn test_makefile_remove_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_remove_phony_target().() { |
| 5956 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = ".PHONY: clean test\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().(); |
| 5957 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.remove_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_phony_target().("clean").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5958 | 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.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("clean")); |
| 5959 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("test")); |
| 5960 | 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.remove_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_phony_target().("nonexistent").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5961 | } |
| 5962 | |
| 5963 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5964 | fn test_makefile_remove_phony_target_lastrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_remove_phony_target_last().() { |
| 5965 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = ".PHONY: clean\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().(); |
| 5966 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.remove_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_phony_target().("clean").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5967 | 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.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("clean")); |
| 5968 | // .PHONY rule should be removed entirely |
| 5969 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().(".PHONY").is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 5970 | } |
| 5971 | |
| 5972 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5973 | fn test_makefile_is_phonyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_is_phony().() { |
| 5974 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = ".PHONY: clean test\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().(); |
| 5975 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("clean")); |
| 5976 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("test")); |
| 5977 | 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.is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().("build")); |
| 5978 | } |
| 5979 | |
| 5980 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5981 | fn test_makefile_phony_targetsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_phony_targets().() { |
| 5982 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = ".PHONY: clean test build\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().(); |
| 5983 | let phony_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.phony_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]phony_targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 5984 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(phony_targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["clean", "test", "build"]); |
| 5985 | } |
| 5986 | |
| 5987 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5988 | fn test_makefile_phony_targets_emptyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_phony_targets_empty().() { |
| 5989 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]new().(); |
| 5990 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.phony_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]phony_targets().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/flatten/impl#[`FlatMap<I, U, F>`][Iterator]count().(), 0); |
| 5991 | } |
| 5992 | |
| 5993 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5994 | fn test_makefile_remove_first_phony_target_no_extra_spacerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_remove_first_phony_target_no_extra_space().() { |
| 5995 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = ".PHONY: clean test build\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().(); |
| 5996 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.remove_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_phony_target().("clean").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 5997 | let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 5998 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, ".PHONY: test build\n"); |
| 5999 | } |
| 6000 | |
| 6001 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6002 | fn test_recipe_with_leading_comments_and_blank_linesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_with_leading_comments_and_blank_lines().() { |
| 6003 | // Regression test for bug where recipes with leading comments and blank lines |
| 6004 | // were not parsed correctly. The parser would stop parsing recipes when it |
| 6005 | // encountered a newline, missing subsequent recipe lines. |
| 6006 | let makefile_text = r#"#!/usr/bin/make |
| 6007 | |
| 6008 | %: |
| 6009 | dh $@ |
| 6010 | |
| 6011 | override_dh_build: |
| 6012 | # The next line is empty |
| 6013 | |
| 6014 | dh_python3 |
| 6015 | "#; |
| 6016 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6017 | |
| 6018 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6019 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2, "Expected 2 rules"); |
| 6020 | |
| 6021 | // First rule: % |
| 6022 | let rule0 = &rules[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().; |
| 6023 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule0.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["%"]); |
| 6024 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule0.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dh $@"]); |
| 6025 | |
| 6026 | // Second rule: override_dh_build |
| 6027 | let rule1 = &rules[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().; |
| 6028 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6029 | rule1.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 6030 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["override_dh_build"] |
| 6031 | ); |
| 6032 | |
| 6033 | // The key assertion: we should have at least the actual command recipe |
| 6034 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule1.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6035 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 6036 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().recipes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 6037 | "Expected at least one recipe for override_dh_build, got none" |
| 6038 | ); |
| 6039 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 6040 | recipes.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"dh_python3".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 6041 | "Expected 'dh_python3' in recipes, got: {:?}", |
| 6042 | recipes |
| 6043 | ); |
| 6044 | } |
| 6045 | |
| 6046 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6047 | fn test_rule_parse_preserves_trailing_blank_linesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_parse_preserves_trailing_blank_lines().() { |
| 6048 | // Regression test: ensure that trailing blank lines are preserved |
| 6049 | // when parsing a rule and using it with replace_rule() |
| 6050 | let input = r#"override_dh_systemd_enable: |
| 6051 | dh_systemd_enable -pracoon |
| 6052 | |
| 6053 | override_dh_install: |
| 6054 | dh_install |
| 6055 | "#; |
| 6056 | |
| 6057 | let mut mf: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.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().(); |
| 6058 | |
| 6059 | // Get first rule and convert to string |
| 6060 | let rule = mf.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 6061 | let rule_text = rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6062 | |
| 6063 | // Should include trailing blank line |
| 6064 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6065 | rule_text, |
| 6066 | "override_dh_systemd_enable:\n\tdh_systemd_enable -pracoon\n\n" |
| 6067 | ); |
| 6068 | |
| 6069 | // Modify the text |
| 6070 | let modified = |
| 6071 | rule_text.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("override_dh_systemd_enable:", "override_dh_installsystemd:"); |
| 6072 | |
| 6073 | // Parse back - should preserve trailing blank line |
| 6074 | let new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = modified.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().(); |
| 6075 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6076 | new_rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 6077 | "override_dh_installsystemd:\n\tdh_systemd_enable -pracoon\n\n" |
| 6078 | ); |
| 6079 | |
| 6080 | // Replace in makefile |
| 6081 | mf.replace_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]replace_rule().(0, new_rule).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6082 | |
| 6083 | // Verify blank line is still present in output |
| 6084 | let output = mf.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6085 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 6086 | output.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().( |
| 6087 | "override_dh_installsystemd:\n\tdh_systemd_enable -pracoon\n\noverride_dh_install:" |
| 6088 | ), |
| 6089 | "Blank line between rules should be preserved. Got: {:?}", |
| 6090 | output |
| 6091 | ); |
| 6092 | } |
| 6093 | |
| 6094 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6095 | fn test_rule_parse_round_trip_with_trailing_newlinesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_parse_round_trip_with_trailing_newlines().() { |
| 6096 | // Test that parsing and stringifying a rule preserves exact trailing newlines |
| 6097 | let test_cases = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 6098 | "rule:\n\tcommand\n", // One newline |
| 6099 | "rule:\n\tcommand\n\n", // Two newlines (blank line) |
| 6100 | "rule:\n\tcommand\n\n\n", // Three newlines (two blank lines) |
| 6101 | ]; |
| 6102 | |
| 6103 | for rule_text in test_cases { |
| 6104 | let rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = rule_text.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().(); |
| 6105 | let result = rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6106 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule_text, result, "Round-trip failed for {:?}", rule_text); |
| 6107 | } |
| 6108 | } |
| 6109 | |
| 6110 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6111 | fn test_rule_clonerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_clone().() { |
| 6112 | // Test that Rule can be cloned and produces an identical copy |
| 6113 | let rule_text = "rule:\n\tcommand\n\n"; |
| 6114 | let rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = rule_text.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().(); |
| 6115 | let cloned = rule.clonerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][Clone]clone().(); |
| 6116 | |
| 6117 | // Both should produce the same string representation |
| 6118 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), cloned.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 6119 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), rule_text); |
| 6120 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cloned.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), rule_text); |
| 6121 | |
| 6122 | // Verify targets and recipes are the same |
| 6123 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6124 | rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 6125 | cloned.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 6126 | ); |
| 6127 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6128 | rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), |
| 6129 | cloned.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 6130 | ); |
| 6131 | } |
| 6132 | |
| 6133 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6134 | fn test_makefile_clonerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_clone().() { |
| 6135 | // Test that Makefile and other AST nodes can be cloned |
| 6136 | let input = "VAR = value\n\nrule:\n\tcommand\n"; |
| 6137 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.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().(); |
| 6138 | let cloned = makefile.clonerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][Clone]clone().(); |
| 6139 | |
| 6140 | // Both should produce the same string representation |
| 6141 | 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().(), cloned.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 6142 | 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().(), input); |
| 6143 | |
| 6144 | // Verify rule count is the same |
| 6145 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), cloned.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()); |
| 6146 | |
| 6147 | // Verify variable definitions are the same |
| 6148 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6149 | makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), |
| 6150 | cloned.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() |
| 6151 | ); |
| 6152 | } |
| 6153 | |
| 6154 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6155 | fn test_conditional_with_recipe_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_with_recipe_line().() { |
| 6156 | // Test that conditionals with recipe lines (tab-indented) work correctly |
| 6157 | let input = "ifeq (,$(X))\n\t./run-tests\nendif\n"; |
| 6158 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 6159 | |
| 6160 | // Should parse without errors |
| 6161 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 6162 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 6163 | "Expected no parse errors, but got: {:?}", |
| 6164 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors. |
| 6165 | ); |
| 6166 | |
| 6167 | // Should preserve the code |
| 6168 | let mf = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 6169 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(mf.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), input); |
| 6170 | } |
| 6171 | |
| 6172 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6173 | fn test_conditional_in_rule_reciperust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_in_rule_recipe().() { |
| 6174 | // Test conditional inside a rule's recipe section |
| 6175 | let input = "override_dh_auto_test:\nifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))\n\t./run-tests\nendif\n"; |
| 6176 | let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(input, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 6177 | |
| 6178 | // Should parse without errors |
| 6179 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 6180 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 6181 | "Expected no parse errors, but got: {:?}", |
| 6182 | parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors. |
| 6183 | ); |
| 6184 | |
| 6185 | // Should preserve the code |
| 6186 | let mf = parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(); |
| 6187 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(mf.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(), input); |
| 6188 | |
| 6189 | // Should have exactly one rule |
| 6190 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(mf.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6191 | } |
| 6192 | |
| 6193 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6194 | fn test_rule_itemsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_items().() { |
| 6195 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#; |
| 6196 | |
| 6197 | // Test rule with both recipes and conditionals |
| 6198 | let input = r#"test: |
| 6199 | echo "before" |
| 6200 | ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) |
| 6201 | ./run-tests |
| 6202 | endif |
| 6203 | echo "after" |
| 6204 | "#; |
| 6205 | let rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = input.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().(); |
| 6206 | |
| 6207 | let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6208 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6209 | items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 6210 | 3, |
| 6211 | "Expected 3 items: recipe, conditional, recipe" |
| 6212 | ); |
| 6213 | |
| 6214 | // Check first item is a recipe |
| 6215 | match &items[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(). { |
| 6216 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Reciperust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Recipe#(r) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r, "echo \"before\""), |
| 6217 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Conditional#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected recipe, got conditional"), |
| 6218 | } |
| 6219 | |
| 6220 | // Check second item is a conditional |
| 6221 | match &items[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(). { |
| 6222 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Conditional#(c) => { |
| 6223 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(c.conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifeq".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6224 | } |
| 6225 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Reciperust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Recipe#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected conditional, got recipe"), |
| 6226 | } |
| 6227 | |
| 6228 | // Check third item is a recipe |
| 6229 | match &items[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). { |
| 6230 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Reciperust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Recipe#(r) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r, "echo \"after\""), |
| 6231 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Conditional#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected recipe, got conditional"), |
| 6232 | } |
| 6233 | |
| 6234 | // Test rule with only recipes (no conditionals) |
| 6235 | let simple_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "simple:\n\techo one\n\techo two\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().(); |
| 6236 | let simple_items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = simple_rule.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6237 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(simple_items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 6238 | |
| 6239 | match &simple_items[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(). { |
| 6240 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Reciperust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Recipe#(r) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r, "echo one"), |
| 6241 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected recipe"), |
| 6242 | } |
| 6243 | |
| 6244 | match &simple_items[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(). { |
| 6245 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Reciperust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Recipe#(r) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r, "echo two"), |
| 6246 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected recipe"), |
| 6247 | } |
| 6248 | |
| 6249 | // Test rule with only conditional (no plain recipes) |
| 6250 | let cond_only: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# = "condtest:\nifeq (a,b)\n\techo yes\nendif\n" |
| 6251 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6252 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6253 | let cond_items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = cond_only.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6254 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cond_items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 6255 | |
| 6256 | match &cond_items[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(). { |
| 6257 | RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Conditional#(c) => { |
| 6258 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(c.conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifeq".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6259 | } |
| 6260 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected conditional"), |
| 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6265 | fn test_conditionals_iteratorrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditionals_iterator().() { |
| 6266 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6267 | VAR = debug |
| 6268 | endif |
| 6269 | |
| 6270 | ifndef RELEASE |
| 6271 | OTHER = dev |
| 6272 | endif |
| 6273 | "# |
| 6274 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6275 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6276 | |
| 6277 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6278 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 6279 | |
| 6280 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6281 | conditionals[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()..conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), |
| 6282 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifdef".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 6283 | ); |
| 6284 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 6285 | conditionals[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()..conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), |
| 6286 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifndef".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 6287 | ); |
| 6288 | } |
| 6289 | |
| 6290 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6291 | fn test_conditional_type_and_conditionrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_type_and_condition().() { |
| 6292 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6293 | VAR = debug |
| 6294 | endif |
| 6295 | "# |
| 6296 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6297 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6298 | |
| 6299 | let conditional = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6300 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditional.conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifdef".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6301 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditional.conditionrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]condition().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("DEBUG".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6302 | } |
| 6303 | |
| 6304 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6305 | fn test_conditional_has_elserust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_has_else().() { |
| 6306 | let makefile_with_else: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6307 | VAR = debug |
| 6308 | else |
| 6309 | VAR = release |
| 6310 | endif |
| 6311 | "# |
| 6312 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6313 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6314 | |
| 6315 | let conditional = makefile_with_else.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6316 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(conditional.has_elserust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]has_else().()); |
| 6317 | |
| 6318 | let makefile_without_else: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6319 | VAR = debug |
| 6320 | endif |
| 6321 | "# |
| 6322 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6323 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6324 | |
| 6325 | let conditional = makefile_without_else.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6326 | 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().conditional.has_elserust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]has_else().()); |
| 6327 | } |
| 6328 | |
| 6329 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6330 | fn test_conditional_if_bodyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_if_body().() { |
| 6331 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6332 | VAR = debug |
| 6333 | endif |
| 6334 | "# |
| 6335 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6336 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6337 | |
| 6338 | let conditional = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6339 | let if_body = conditional.if_bodyrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]if_body().(); |
| 6340 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(if_body.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 6341 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(if_body.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = debug")); |
| 6342 | } |
| 6343 | |
| 6344 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6345 | fn test_conditional_else_bodyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_else_body().() { |
| 6346 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6347 | VAR = debug |
| 6348 | else |
| 6349 | VAR = release |
| 6350 | endif |
| 6351 | "# |
| 6352 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6353 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6354 | |
| 6355 | let conditional = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6356 | let else_body = conditional.else_bodyrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]else_body().(); |
| 6357 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(else_body.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 6358 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(else_body.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = release")); |
| 6359 | } |
| 6360 | |
| 6361 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6362 | fn test_add_conditional_ifdefrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_conditional_ifdef().() { |
| 6363 | 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().(); |
| 6364 | let result = makefile.add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().("ifdef", "DEBUG", "VAR = debug\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 6365 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 6366 | |
| 6367 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6368 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 6369 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = debug")); |
| 6370 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 6371 | } |
| 6372 | |
| 6373 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6374 | fn test_add_conditional_with_elserust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_conditional_with_else().() { |
| 6375 | 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().(); |
| 6376 | let result = |
| 6377 | makefile.add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().("ifdef", "DEBUG", "VAR = debug\n", Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("VAR = release\n")); |
| 6378 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 6379 | |
| 6380 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6381 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 6382 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = debug")); |
| 6383 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else")); |
| 6384 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = release")); |
| 6385 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 6386 | } |
| 6387 | |
| 6388 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6389 | fn test_add_conditional_invalid_typerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_conditional_invalid_type().() { |
| 6390 | 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().(); |
| 6391 | let result = makefile.add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().("invalid", "DEBUG", "VAR = debug\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 6392 | 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().()); |
| 6393 | } |
| 6394 | |
| 6395 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6396 | fn test_add_conditional_formattingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_conditional_formatting().() { |
| 6397 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = value1\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().(); |
| 6398 | let result = makefile.add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().("ifdef", "DEBUG", "VAR = debug\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 6399 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 6400 | |
| 6401 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6402 | // Should have a blank line before the conditional |
| 6403 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("\n\nifdef DEBUG")); |
| 6404 | } |
| 6405 | |
| 6406 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6407 | fn test_conditional_removerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_remove().() { |
| 6408 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6409 | VAR = debug |
| 6410 | endif |
| 6411 | |
| 6412 | VAR2 = value2 |
| 6413 | "# |
| 6414 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6415 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6416 | |
| 6417 | let mut conditional = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6418 | let result = conditional.removerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]remove().(); |
| 6419 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 6420 | |
| 6421 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6422 | 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().code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 6423 | 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().code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = debug")); |
| 6424 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR2 = value2")); |
| 6425 | } |
| 6426 | |
| 6427 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6428 | fn test_add_conditional_ifndefrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_conditional_ifndef().() { |
| 6429 | 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().(); |
| 6430 | let result = makefile.add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().("ifndef", "NDEBUG", "VAR = enabled\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 6431 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 6432 | |
| 6433 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6434 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifndef NDEBUG")); |
| 6435 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = enabled")); |
| 6436 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 6437 | } |
| 6438 | |
| 6439 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6440 | fn test_add_conditional_ifeqrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_conditional_ifeq().() { |
| 6441 | 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().(); |
| 6442 | let result = makefile.add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().("ifeq", "($(OS),Linux)", "VAR = linux\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 6443 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 6444 | |
| 6445 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6446 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifeq ($(OS),Linux)")); |
| 6447 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = linux")); |
| 6448 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 6449 | } |
| 6450 | |
| 6451 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6452 | fn test_add_conditional_ifneqrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_conditional_ifneq().() { |
| 6453 | 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().(); |
| 6454 | let result = makefile.add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().("ifneq", "($(OS),Windows)", "VAR = unix\n", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 6455 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 6456 | |
| 6457 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6458 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifneq ($(OS),Windows)")); |
| 6459 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("VAR = unix")); |
| 6460 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("endif")); |
| 6461 | } |
| 6462 | |
| 6463 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6464 | fn test_conditional_api_integrationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_api_integration().() { |
| 6465 | // Create a makefile with a rule and a variable |
| 6466 | let mut makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR1 = value1 |
| 6467 | |
| 6468 | rule1: |
| 6469 | command1 |
| 6470 | "# |
| 6471 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6472 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6473 | |
| 6474 | // Add a conditional |
| 6475 | makefile |
| 6476 | .add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().("ifdef", "DEBUG", "CFLAGS += -g\n", Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("CFLAGS += -O2\n")) |
| 6477 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6478 | |
| 6479 | // Verify the conditional was added |
| 6480 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6481 | let conditional = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6482 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditional.conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifdef".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6483 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditional.conditionrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]condition().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("DEBUG".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6484 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(conditional.has_elserust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]has_else().()); |
| 6485 | |
| 6486 | // Verify the original content is preserved |
| 6487 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6488 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6489 | } |
| 6490 | |
| 6491 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6492 | fn test_conditional_if_itemsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_if_items().() { |
| 6493 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6494 | VAR = debug |
| 6495 | rule: |
| 6496 | command |
| 6497 | endif |
| 6498 | "# |
| 6499 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6500 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6501 | |
| 6502 | let cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6503 | let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = cond.if_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]if_items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6504 | 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().(), 2); // One variable, one rule |
| 6505 | |
| 6506 | match &items[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(). { |
| 6507 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(v) => { |
| 6508 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.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().())); |
| 6509 | } |
| 6510 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected variable"), |
| 6511 | } |
| 6512 | |
| 6513 | match &items[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(). { |
| 6514 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(r) => { |
| 6515 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t == "rule")); |
| 6516 | } |
| 6517 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected rule"), |
| 6518 | } |
| 6519 | } |
| 6520 | |
| 6521 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6522 | fn test_conditional_else_itemsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_else_items().() { |
| 6523 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6524 | VAR = debug |
| 6525 | else |
| 6526 | VAR2 = release |
| 6527 | rule2: |
| 6528 | command |
| 6529 | endif |
| 6530 | "# |
| 6531 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6532 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6533 | |
| 6534 | let cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6535 | let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = cond.else_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]else_items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6536 | 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().(), 2); // One variable, one rule |
| 6537 | |
| 6538 | match &items[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(). { |
| 6539 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(v) => { |
| 6540 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.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#("VAR2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6541 | } |
| 6542 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected variable"), |
| 6543 | } |
| 6544 | |
| 6545 | match &items[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(). { |
| 6546 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(r) => { |
| 6547 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t == "rule2")); |
| 6548 | } |
| 6549 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected rule"), |
| 6550 | } |
| 6551 | } |
| 6552 | |
| 6553 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6554 | fn test_conditional_add_if_itemrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_add_if_item().() { |
| 6555 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "ifdef DEBUG\nendif\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().(); |
| 6556 | let mut cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6557 | |
| 6558 | // Parse a variable from a temporary makefile |
| 6559 | let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = -g\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().(); |
| 6560 | let var = temp.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().(); |
| 6561 | cond.add_if_itemrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]add_if_item().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(var)); |
| 6562 | |
| 6563 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6564 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("CFLAGS = -g")); |
| 6565 | |
| 6566 | // Verify it's in the if branch |
| 6567 | let cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6568 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cond.if_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]if_items().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6569 | } |
| 6570 | |
| 6571 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6572 | fn test_conditional_add_else_itemrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_add_else_item().() { |
| 6573 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "ifdef DEBUG\nVAR=1\nendif\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().(); |
| 6574 | let mut cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6575 | |
| 6576 | // Parse a variable from a temporary makefile |
| 6577 | let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = -O2\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().(); |
| 6578 | let var = temp.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().(); |
| 6579 | cond.add_else_itemrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]add_else_item().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(var)); |
| 6580 | |
| 6581 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6582 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else")); |
| 6583 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("CFLAGS = -O2")); |
| 6584 | |
| 6585 | // Verify it's in the else branch |
| 6586 | let cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6587 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cond.else_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]else_items().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6588 | } |
| 6589 | |
| 6590 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6591 | fn test_add_conditional_with_itemsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_add_conditional_with_items().() { |
| 6592 | 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().(); |
| 6593 | |
| 6594 | // Parse items from temporary makefiles |
| 6595 | let temp1: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = -g\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().(); |
| 6596 | let var1 = temp1.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().(); |
| 6597 | |
| 6598 | let temp2: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = -O2\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().(); |
| 6599 | let var2 = temp2.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().(); |
| 6600 | |
| 6601 | let temp3: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "debug:\n\techo debug\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().(); |
| 6602 | let rule1 = temp3.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 6603 | |
| 6604 | let result = makefile.add_conditional_with_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional_with_items().( |
| 6605 | "ifdef", |
| 6606 | "DEBUG", |
| 6607 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(var1), MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(rule1)], |
| 6608 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(var2)]), |
| 6609 | ); |
| 6610 | |
| 6611 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 6612 | |
| 6613 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6614 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 6615 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("CFLAGS = -g")); |
| 6616 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("debug:")); |
| 6617 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("else")); |
| 6618 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(code.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("CFLAGS = -O2")); |
| 6619 | } |
| 6620 | |
| 6621 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6622 | fn test_conditional_items_with_nested_conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_items_with_nested_conditional().() { |
| 6623 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6624 | VAR = debug |
| 6625 | ifdef VERBOSE |
| 6626 | VAR2 = verbose |
| 6627 | endif |
| 6628 | endif |
| 6629 | "# |
| 6630 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6631 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6632 | |
| 6633 | let cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6634 | let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = cond.if_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]if_items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6635 | 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().(), 2); // One variable, one nested conditional |
| 6636 | |
| 6637 | match &items[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(). { |
| 6638 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(v) => { |
| 6639 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.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().())); |
| 6640 | } |
| 6641 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected variable"), |
| 6642 | } |
| 6643 | |
| 6644 | match &items[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(). { |
| 6645 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(c) => { |
| 6646 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(c.conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifdef".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6647 | } |
| 6648 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected conditional"), |
| 6649 | } |
| 6650 | } |
| 6651 | |
| 6652 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6653 | fn test_conditional_items_with_includerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_items_with_include().() { |
| 6654 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6655 | include debug.mk |
| 6656 | VAR = debug |
| 6657 | endif |
| 6658 | "# |
| 6659 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6660 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6661 | |
| 6662 | let cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6663 | let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = cond.if_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]if_items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6664 | 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().(), 2); // One include, one variable |
| 6665 | |
| 6666 | match &items[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(). { |
| 6667 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Include#(i) => { |
| 6668 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i.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#("debug.mk".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6669 | } |
| 6670 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected include"), |
| 6671 | } |
| 6672 | |
| 6673 | match &items[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(). { |
| 6674 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(v) => { |
| 6675 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.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().())); |
| 6676 | } |
| 6677 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected variable"), |
| 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6682 | fn test_makefile_items_iteratorrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_makefile_items_iterator().() { |
| 6683 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"VAR = value |
| 6684 | ifdef DEBUG |
| 6685 | CFLAGS = -g |
| 6686 | endif |
| 6687 | rule: |
| 6688 | command |
| 6689 | include common.mk |
| 6690 | "# |
| 6691 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6692 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6693 | |
| 6694 | // First verify we can find each type individually |
| 6695 | // variable_definitions() is recursive, so it finds VAR and CFLAGS (inside conditional) |
| 6696 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2); |
| 6697 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6698 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6699 | |
| 6700 | 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().(); |
| 6701 | // Note: include directives might not be at top level, need to check |
| 6702 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 6703 | items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() >= 3, |
| 6704 | "Expected at least 3 items, got {}", |
| 6705 | items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 6706 | ); |
| 6707 | |
| 6708 | match &items[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(). { |
| 6709 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(v) => { |
| 6710 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v.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().())); |
| 6711 | } |
| 6712 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected variable at position 0"), |
| 6713 | } |
| 6714 | |
| 6715 | match &items[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(). { |
| 6716 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(c) => { |
| 6717 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(c.conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifdef".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 6718 | } |
| 6719 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected conditional at position 1"), |
| 6720 | } |
| 6721 | |
| 6722 | match &items[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). { |
| 6723 | MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(r) => { |
| 6724 | let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6725 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["rule"]); |
| 6726 | } |
| 6727 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected rule at position 2"), |
| 6728 | } |
| 6729 | } |
| 6730 | |
| 6731 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6732 | fn test_conditional_unwraprust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_unwrap().() { |
| 6733 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6734 | VAR = debug |
| 6735 | rule: |
| 6736 | command |
| 6737 | endif |
| 6738 | "# |
| 6739 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6740 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6741 | |
| 6742 | let mut cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6743 | cond.unwraprust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6744 | |
| 6745 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6746 | let expected = "VAR = debug\nrule:\n\tcommand\n"; |
| 6747 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, expected); |
| 6748 | |
| 6749 | // Should have no conditionals now |
| 6750 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 6751 | |
| 6752 | // Should still have the variable and rule |
| 6753 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6754 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 6755 | } |
| 6756 | |
| 6757 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6758 | fn test_conditional_unwrap_with_else_failsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_unwrap_with_else_fails().() { |
| 6759 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6760 | VAR = debug |
| 6761 | else |
| 6762 | VAR = release |
| 6763 | endif |
| 6764 | "# |
| 6765 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6766 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6767 | |
| 6768 | let mut cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6769 | let result = cond.unwraprust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]unwrap().(); |
| 6770 | |
| 6771 | 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().()); |
| 6772 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result |
| 6773 | .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().() |
| 6774 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 6775 | .containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Cannot unwrap conditional with else clause")); |
| 6776 | } |
| 6777 | |
| 6778 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6779 | fn test_conditional_unwrap_nestedrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_unwrap_nested().() { |
| 6780 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef OUTER |
| 6781 | VAR = outer |
| 6782 | ifdef INNER |
| 6783 | VAR2 = inner |
| 6784 | endif |
| 6785 | endif |
| 6786 | "# |
| 6787 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6788 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6789 | |
| 6790 | // Unwrap the outer conditional |
| 6791 | let mut outer_cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6792 | outer_cond.unwraprust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6793 | |
| 6794 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6795 | let expected = "VAR = outer\nifdef INNER\nVAR2 = inner\nendif\n"; |
| 6796 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, expected); |
| 6797 | } |
| 6798 | |
| 6799 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6800 | fn test_conditional_unwrap_emptyrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_unwrap_empty().() { |
| 6801 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6802 | endif |
| 6803 | "# |
| 6804 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6805 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6806 | |
| 6807 | let mut cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6808 | cond.unwraprust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6809 | |
| 6810 | let code = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 6811 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(code, ""); |
| 6812 | } |
| 6813 | |
| 6814 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6815 | fn test_rule_parentrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_rule_parent().() { |
| 6816 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"all: |
| 6817 | echo "test" |
| 6818 | "# |
| 6819 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6820 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6821 | |
| 6822 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 6823 | let parent = rule.parentrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]parent().(); |
| 6824 | // Parent is ROOT node which doesn't cast to MakefileItem |
| 6825 | 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().()); |
| 6826 | } |
| 6827 | |
| 6828 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6829 | fn test_item_parent_in_conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_item_parent_in_conditional().() { |
| 6830 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef DEBUG |
| 6831 | VAR = debug |
| 6832 | rule: |
| 6833 | command |
| 6834 | endif |
| 6835 | "# |
| 6836 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6837 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6838 | |
| 6839 | let cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6840 | |
| 6841 | // Get items from the conditional |
| 6842 | let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = cond.if_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]if_items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6843 | 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().(), 2); |
| 6844 | |
| 6845 | // Check variable parent is the conditional |
| 6846 | if let MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(var) = &items[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(). { |
| 6847 | let parent = var.parentrust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]parent().(); |
| 6848 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parent.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 6849 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(_)) = parent { |
| 6850 | // Expected - parent is a conditional |
| 6851 | } else { |
| 6852 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected variable parent to be a Conditional"); |
| 6853 | } |
| 6854 | } else { |
| 6855 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected first item to be a Variable"); |
| 6856 | } |
| 6857 | |
| 6858 | // Check rule parent is the conditional |
| 6859 | if let MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(rule) = &items[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(). { |
| 6860 | let parent = rule.parentrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]parent().(); |
| 6861 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parent.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 6862 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(_)) = parent { |
| 6863 | // Expected - parent is a conditional |
| 6864 | } else { |
| 6865 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected rule parent to be a Conditional"); |
| 6866 | } |
| 6867 | } else { |
| 6868 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected second item to be a Rule"); |
| 6869 | } |
| 6870 | } |
| 6871 | |
| 6872 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6873 | fn test_nested_conditional_parentrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_nested_conditional_parent().() { |
| 6874 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"ifdef OUTER |
| 6875 | VAR = outer |
| 6876 | ifdef INNER |
| 6877 | VAR2 = inner |
| 6878 | endif |
| 6879 | endif |
| 6880 | "# |
| 6881 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 6882 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 6883 | |
| 6884 | let outer_cond = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().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().(); |
| 6885 | |
| 6886 | // Get inner conditional from outer conditional's items |
| 6887 | let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = outer_cond.if_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]if_items().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6888 | |
| 6889 | // Find the nested conditional |
| 6890 | let inner_cond = items |
| 6891 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 6892 | .find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find_map().(|item| { |
| 6893 | if let MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(c) = item { |
| 6894 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) |
| 6895 | } else { |
| 6896 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 6897 | } |
| 6898 | }) |
| 6899 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 6900 | |
| 6901 | // Inner conditional's parent should be the outer conditional |
| 6902 | let parent = inner_cond.parentrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]parent().(); |
| 6903 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(parent.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()); |
| 6904 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(_)) = parent { |
| 6905 | // Expected - parent is a conditional |
| 6906 | } else { |
| 6907 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected inner conditional's parent to be a Conditional"); |
| 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6912 | fn test_line_colrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_line_col().() { |
| 6913 | let text = r#"# Comment at line 0 |
| 6914 | VAR1 = value1 |
| 6915 | VAR2 = value2 |
| 6916 | |
| 6917 | rule1: dep1 dep2 |
| 6918 | command1 |
| 6919 | command2 |
| 6920 | |
| 6921 | rule2: |
| 6922 | command3 |
| 6923 | |
| 6924 | ifdef DEBUG |
| 6925 | CFLAGS = -g |
| 6926 | endif |
| 6927 | "#; |
| 6928 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 6929 | |
| 6930 | // Test variable definition line numbers |
| 6931 | // variable_definitions() is recursive, so it finds VAR1, VAR2, and CFLAGS (inside conditional) |
| 6932 | 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().(); |
| 6933 | 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().(), 3); |
| 6934 | |
| 6935 | // VAR1 starts at line 1 |
| 6936 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 1); |
| 6937 | 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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]column().(), 0); |
| 6938 | 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()..line_colrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line_col().(), (1, 0)); |
| 6939 | |
| 6940 | // VAR2 starts at line 2 |
| 6941 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 2); |
| 6942 | 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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]column().(), 0); |
| 6943 | |
| 6944 | // CFLAGS starts at line 12 (inside ifdef DEBUG) |
| 6945 | 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().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 12); |
| 6946 | 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().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]column().(), 0); |
| 6947 | |
| 6948 | // Test rule line numbers |
| 6949 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6950 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 6951 | |
| 6952 | // rule1 starts at line 4 |
| 6953 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule]line().(), 4); |
| 6954 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule]column().(), 0); |
| 6955 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..line_colrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule]line_col().(), (4, 0)); |
| 6956 | |
| 6957 | // rule2 starts at line 8 |
| 6958 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule]line().(), 8); |
| 6959 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule]column().(), 0); |
| 6960 | |
| 6961 | // Test conditional line numbers |
| 6962 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6963 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 6964 | |
| 6965 | // ifdef DEBUG starts at line 11 |
| 6966 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 11); |
| 6967 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]column().(), 0); |
| 6968 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..line_colrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line_col().(), (11, 0)); |
| 6969 | } |
| 6970 | |
| 6971 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6972 | fn test_line_col_multilinerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_line_col_multiline().() { |
| 6973 | let text = "SOURCES = \\\n\tfile1.c \\\n\tfile2.c\n\ntarget: $(SOURCES)\n\tgcc -o target $(SOURCES)\n"; |
| 6974 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 6975 | |
| 6976 | // Variable definition starts at line 0 |
| 6977 | 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().(); |
| 6978 | 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().(), 1); |
| 6979 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 0); |
| 6980 | 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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]column().(), 0); |
| 6981 | |
| 6982 | // Rule starts at line 4 |
| 6983 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 6984 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 6985 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule]line().(), 4); |
| 6986 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule]column().(), 0); |
| 6987 | } |
| 6988 | |
| 6989 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6990 | fn test_line_col_includesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_line_col_includes().() { |
| 6991 | let text = "VAR = value\n\ninclude config.mk\n-include optional.mk\n"; |
| 6992 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 6993 | |
| 6994 | // Variable at line 0 |
| 6995 | 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().(); |
| 6996 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 0); |
| 6997 | |
| 6998 | // Includes at lines 2 and 3 |
| 6999 | 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().(); |
| 7000 | 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().(), 2); |
| 7001 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include]line().(), 2); |
| 7002 | 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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include]column().(), 0); |
| 7003 | 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().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include]line().(), 3); |
| 7004 | 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().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include]column().(), 0); |
| 7005 | } |
| 7006 | |
| 7007 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7008 | fn test_conditional_in_rule_vs_toplevelrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_in_rule_vs_toplevel().() { |
| 7009 | // Conditional immediately after rule (no blank line) - part of rule |
| 7010 | let text1 = r#"rule: |
| 7011 | command |
| 7012 | ifeq (,$(X)) |
| 7013 | test |
| 7014 | endif |
| 7015 | "#; |
| 7016 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text1.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().(); |
| 7017 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7018 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7019 | |
| 7020 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7021 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7022 | conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 7023 | 0, |
| 7024 | "Conditional should be part of rule, not top-level" |
| 7025 | ); |
| 7026 | |
| 7027 | // Conditional after blank line - top-level |
| 7028 | let text2 = r#"rule: |
| 7029 | command |
| 7030 | |
| 7031 | ifeq (,$(X)) |
| 7032 | test |
| 7033 | endif |
| 7034 | "#; |
| 7035 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text2.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().(); |
| 7036 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7037 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7038 | |
| 7039 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7040 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7041 | conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 7042 | 1, |
| 7043 | "Conditional after blank line should be top-level" |
| 7044 | ); |
| 7045 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 3); |
| 7046 | } |
| 7047 | |
| 7048 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7049 | fn test_nested_conditionals_line_trackingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_nested_conditionals_line_tracking().() { |
| 7050 | let text = r#"ifdef OUTER |
| 7051 | VAR1 = value1 |
| 7052 | ifdef INNER |
| 7053 | VAR2 = value2 |
| 7054 | endif |
| 7055 | VAR3 = value3 |
| 7056 | endif |
| 7057 | "#; |
| 7058 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7059 | |
| 7060 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7061 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7062 | conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), |
| 7063 | 1, |
| 7064 | "Only outer conditional should be top-level" |
| 7065 | ); |
| 7066 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 0); |
| 7067 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]column().(), 0); |
| 7068 | } |
| 7069 | |
| 7070 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7071 | fn test_conditional_else_line_trackingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_else_line_tracking().() { |
| 7072 | let text = r#"VAR1 = before |
| 7073 | |
| 7074 | ifdef DEBUG |
| 7075 | DEBUG_FLAGS = -g |
| 7076 | else |
| 7077 | DEBUG_FLAGS = -O2 |
| 7078 | endif |
| 7079 | |
| 7080 | VAR2 = after |
| 7081 | "#; |
| 7082 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7083 | |
| 7084 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7085 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7086 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 2); |
| 7087 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]column().(), 0); |
| 7088 | } |
| 7089 | |
| 7090 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7091 | fn test_broken_conditional_endif_without_ifrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_broken_conditional_endif_without_if().() { |
| 7092 | // endif without matching if - parser should handle gracefully |
| 7093 | let text = "VAR = value\nendif\n"; |
| 7094 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7095 | |
| 7096 | // Should parse without crashing |
| 7097 | 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().(); |
| 7098 | 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().(), 1); |
| 7099 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 0); |
| 7100 | } |
| 7101 | |
| 7102 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7103 | fn test_broken_conditional_else_without_ifrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_broken_conditional_else_without_if().() { |
| 7104 | // else without matching if |
| 7105 | let text = "VAR = value\nelse\nVAR2 = other\n"; |
| 7106 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7107 | |
| 7108 | // Should parse without crashing |
| 7109 | 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().(); |
| 7110 | 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.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Should parse at least the first variable"); |
| 7111 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 0); |
| 7112 | } |
| 7113 | |
| 7114 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7115 | fn test_broken_conditional_missing_endifrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_broken_conditional_missing_endif().() { |
| 7116 | // ifdef without matching endif |
| 7117 | let text = r#"ifdef DEBUG |
| 7118 | DEBUG_FLAGS = -g |
| 7119 | VAR = value |
| 7120 | "#; |
| 7121 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7122 | |
| 7123 | // Should parse without crashing |
| 7124 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 7125 | } |
| 7126 | |
| 7127 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7128 | fn test_multiple_conditionals_line_trackingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_multiple_conditionals_line_tracking().() { |
| 7129 | let text = r#"ifdef A |
| 7130 | VAR_A = a |
| 7131 | endif |
| 7132 | |
| 7133 | ifdef B |
| 7134 | VAR_B = b |
| 7135 | endif |
| 7136 | |
| 7137 | ifdef C |
| 7138 | VAR_C = c |
| 7139 | endif |
| 7140 | "#; |
| 7141 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7142 | |
| 7143 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7144 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3); |
| 7145 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 0); |
| 7146 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 4); |
| 7147 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 8); |
| 7148 | } |
| 7149 | |
| 7150 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7151 | fn test_conditional_with_multiple_else_ifeqrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_with_multiple_else_ifeq().() { |
| 7152 | let text = r#"ifeq ($(OS),Windows) |
| 7153 | EXT = .exe |
| 7154 | else ifeq ($(OS),Linux) |
| 7155 | EXT = .bin |
| 7156 | else |
| 7157 | EXT = .out |
| 7158 | endif |
| 7159 | "#; |
| 7160 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7161 | |
| 7162 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7163 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7164 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 0); |
| 7165 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]column().(), 0); |
| 7166 | } |
| 7167 | |
| 7168 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7169 | fn test_conditional_types_line_trackingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_types_line_tracking().() { |
| 7170 | let text = r#"ifdef VAR1 |
| 7171 | A = 1 |
| 7172 | endif |
| 7173 | |
| 7174 | ifndef VAR2 |
| 7175 | B = 2 |
| 7176 | endif |
| 7177 | |
| 7178 | ifeq ($(X),y) |
| 7179 | C = 3 |
| 7180 | endif |
| 7181 | |
| 7182 | ifneq ($(Y),n) |
| 7183 | D = 4 |
| 7184 | endif |
| 7185 | "#; |
| 7186 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7187 | |
| 7188 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7189 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 4); |
| 7190 | |
| 7191 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 0); // ifdef |
| 7192 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7193 | conditionals[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()..conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), |
| 7194 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifdef".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 7195 | ); |
| 7196 | |
| 7197 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 4); // ifndef |
| 7198 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7199 | conditionals[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()..conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), |
| 7200 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifndef".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 7201 | ); |
| 7202 | |
| 7203 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 8); // ifeq |
| 7204 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifeq".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 7205 | |
| 7206 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 12); // ifneq |
| 7207 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7208 | conditionals[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..conditional_typerust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]conditional_type().(), |
| 7209 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("ifneq".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 7210 | ); |
| 7211 | } |
| 7212 | |
| 7213 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7214 | fn test_conditional_in_rule_with_recipesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_in_rule_with_recipes().() { |
| 7215 | let text = r#"test: |
| 7216 | echo "start" |
| 7217 | ifdef VERBOSE |
| 7218 | echo "verbose mode" |
| 7219 | endif |
| 7220 | echo "end" |
| 7221 | "#; |
| 7222 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7223 | |
| 7224 | let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7225 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7226 | |
| 7227 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7228 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule]line().(), 0); |
| 7229 | // Conditional is part of the rule, not top-level |
| 7230 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0); |
| 7231 | } |
| 7232 | |
| 7233 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7234 | fn test_broken_conditional_double_elserust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_broken_conditional_double_else().() { |
| 7235 | // Two else clauses in one conditional |
| 7236 | let text = r#"ifdef DEBUG |
| 7237 | A = 1 |
| 7238 | else |
| 7239 | B = 2 |
| 7240 | else |
| 7241 | C = 3 |
| 7242 | endif |
| 7243 | "#; |
| 7244 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7245 | |
| 7246 | // Should parse without crashing, though it's malformed |
| 7247 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("ifdef DEBUG")); |
| 7248 | } |
| 7249 | |
| 7250 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7251 | fn test_broken_conditional_mismatched_nestingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_broken_conditional_mismatched_nesting().() { |
| 7252 | // Mismatched nesting - more endifs than ifs |
| 7253 | let text = r#"ifdef A |
| 7254 | VAR = value |
| 7255 | endif |
| 7256 | endif |
| 7257 | "#; |
| 7258 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(&mut text.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7259 | |
| 7260 | // Should parse without crashing |
| 7261 | // The extra endif will be parsed separately, so we may get more than 1 item |
| 7262 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7263 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 7264 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().conditionals.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), |
| 7265 | "Should parse at least the first conditional" |
| 7266 | ); |
| 7267 | } |
| 7268 | |
| 7269 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7270 | fn test_conditional_with_comment_line_trackingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_with_comment_line_tracking().() { |
| 7271 | let text = r#"# This is a comment |
| 7272 | ifdef DEBUG |
| 7273 | # Another comment |
| 7274 | CFLAGS = -g |
| 7275 | endif |
| 7276 | # Final comment |
| 7277 | "#; |
| 7278 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7279 | |
| 7280 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7281 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7282 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 1); |
| 7283 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]column().(), 0); |
| 7284 | } |
| 7285 | |
| 7286 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7287 | fn test_conditional_after_variable_with_blank_linesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_conditional_after_variable_with_blank_lines().() { |
| 7288 | let text = r#"VAR1 = value1 |
| 7289 | |
| 7290 | |
| 7291 | ifdef DEBUG |
| 7292 | VAR2 = value2 |
| 7293 | endif |
| 7294 | "#; |
| 7295 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7296 | |
| 7297 | 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().(); |
| 7298 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7299 | |
| 7300 | // variable_definitions() is recursive, so it finds VAR1 and VAR2 (inside conditional) |
| 7301 | 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); |
| 7302 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 0); // VAR1 |
| 7303 | 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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition]line().(), 4); // VAR2 |
| 7304 | |
| 7305 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7306 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 3); |
| 7307 | } |
| 7308 | |
| 7309 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7310 | fn test_empty_conditional_line_trackingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_empty_conditional_line_tracking().() { |
| 7311 | let text = r#"ifdef DEBUG |
| 7312 | endif |
| 7313 | |
| 7314 | ifndef RELEASE |
| 7315 | endif |
| 7316 | "#; |
| 7317 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7318 | |
| 7319 | let conditionals: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7320 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 7321 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 0); |
| 7322 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(conditionals[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional]line().(), 3); |
| 7323 | } |
| 7324 | |
| 7325 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7326 | fn test_recipe_line_trackingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_line_tracking().() { |
| 7327 | let text = r#"build: |
| 7328 | echo "Building..." |
| 7329 | gcc -o app main.c |
| 7330 | echo "Done" |
| 7331 | |
| 7332 | test: |
| 7333 | ./run-tests |
| 7334 | "#; |
| 7335 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7336 | |
| 7337 | // Test first rule's recipes |
| 7338 | let rule1 = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have first rule"); |
| 7339 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule1.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7340 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3); |
| 7341 | |
| 7342 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo \"Building...\""); |
| 7343 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]line().(), 1); |
| 7344 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]column().(), 0); |
| 7345 | |
| 7346 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "gcc -o app main.c"); |
| 7347 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]line().(), 2); |
| 7348 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]column().(), 0); |
| 7349 | |
| 7350 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo \"Done\""); |
| 7351 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]line().(), 3); |
| 7352 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]column().(), 0); |
| 7353 | |
| 7354 | // Test second rule's recipes |
| 7355 | let rule2 = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have second rule"); |
| 7356 | let recipes2: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule2.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7357 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes2.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7358 | |
| 7359 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes2[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "./run-tests"); |
| 7360 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes2[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]line().(), 6); |
| 7361 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes2[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]column().(), 0); |
| 7362 | } |
| 7363 | |
| 7364 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7365 | fn test_recipe_with_variables_line_trackingrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_with_variables_line_tracking().() { |
| 7366 | let text = r#"install: |
| 7367 | mkdir -p $(DESTDIR) |
| 7368 | cp $(BINARY) $(DESTDIR)/ |
| 7369 | "#; |
| 7370 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7371 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have rule"); |
| 7372 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7373 | |
| 7374 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 7375 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]line().(), 1); |
| 7376 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]line().(), 2); |
| 7377 | } |
| 7378 | |
| 7379 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7380 | fn test_recipe_text_no_leading_tabrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_text_no_leading_tab().() { |
| 7381 | // Test that Recipe::text() does not include the leading tab |
| 7382 | let text = "test:\n\techo hello\n\t\techo nested\n\t echo with spaces\n"; |
| 7383 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = text.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().(); |
| 7384 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Should have rule"); |
| 7385 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7386 | |
| 7387 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3); |
| 7388 | |
| 7389 | // Debug: print syntax tree for the first recipe |
| 7390 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Recipe 0 syntax tree:\n{:#?}", recipes[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()..syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().()); |
| 7391 | |
| 7392 | // First recipe: single tab |
| 7393 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo hello"); |
| 7394 | |
| 7395 | // Second recipe: double tab (nested) |
| 7396 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Recipe 1 syntax tree:\n{:#?}", recipes[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()..syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().()); |
| 7397 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "\techo nested"); |
| 7398 | |
| 7399 | // Third recipe: tab followed by spaces |
| 7400 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Recipe 2 syntax tree:\n{:#?}", recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]syntax().()); |
| 7401 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), " echo with spaces"); |
| 7402 | } |
| 7403 | |
| 7404 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7405 | fn test_recipe_parentrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_parent().() { |
| 7406 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all: dep\n\techo hello\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().(); |
| 7407 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7408 | let recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7409 | |
| 7410 | let parent = recipe.parentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]parent().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Recipe should have parent"); |
| 7411 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parent.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["all"]); |
| 7412 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parent.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["dep"]); |
| 7413 | } |
| 7414 | |
| 7415 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7416 | fn test_recipe_is_silent_various_prefixesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_is_silent_various_prefixes().() { |
| 7417 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"test: |
| 7418 | @echo silent |
| 7419 | -echo ignore |
| 7420 | +echo always |
| 7421 | @-echo silent_ignore |
| 7422 | -@echo ignore_silent |
| 7423 | +@echo always_silent |
| 7424 | echo normal |
| 7425 | "# |
| 7426 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 7427 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7428 | |
| 7429 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7430 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7431 | |
| 7432 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 7); |
| 7433 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[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_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().(), "@echo should be silent"); |
| 7434 | 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().recipes[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_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().(), "-echo should not be silent"); |
| 7435 | 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().recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().(), "+echo should not be silent"); |
| 7436 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().(), "@-echo should be silent"); |
| 7437 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().4]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().(), "-@echo should be silent"); |
| 7438 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().5]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().(), "+@echo should be silent"); |
| 7439 | 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().recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().6]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().(), "echo should not be silent"); |
| 7440 | } |
| 7441 | |
| 7442 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7443 | fn test_recipe_is_ignore_errors_various_prefixesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_is_ignore_errors_various_prefixes().() { |
| 7444 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = r#"test: |
| 7445 | @echo silent |
| 7446 | -echo ignore |
| 7447 | +echo always |
| 7448 | @-echo silent_ignore |
| 7449 | -@echo ignore_silent |
| 7450 | +-echo always_ignore |
| 7451 | echo normal |
| 7452 | "# |
| 7453 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 7454 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7455 | |
| 7456 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7457 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7458 | |
| 7459 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 7); |
| 7460 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 7461 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().recipes[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_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().(), |
| 7462 | "@echo should not ignore errors" |
| 7463 | ); |
| 7464 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[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_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().(), "-echo should ignore errors"); |
| 7465 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 7466 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().(), |
| 7467 | "+echo should not ignore errors" |
| 7468 | ); |
| 7469 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().(), "@-echo should ignore errors"); |
| 7470 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().4]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().(), "-@echo should ignore errors"); |
| 7471 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().5]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().(), "+-echo should ignore errors"); |
| 7472 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 7473 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().6]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().(), |
| 7474 | "echo should not ignore errors" |
| 7475 | ); |
| 7476 | } |
| 7477 | |
| 7478 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7479 | fn test_recipe_set_prefix_addrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_set_prefix_add().() { |
| 7480 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo hello\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().(); |
| 7481 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7482 | let mut recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7483 | |
| 7484 | recipe.set_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]set_prefix().("@"); |
| 7485 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "@echo hello"); |
| 7486 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipe.is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().()); |
| 7487 | } |
| 7488 | |
| 7489 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7490 | fn test_recipe_set_prefix_changerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_set_prefix_change().() { |
| 7491 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\t@echo hello\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().(); |
| 7492 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7493 | let mut recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7494 | |
| 7495 | recipe.set_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]set_prefix().("-"); |
| 7496 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "-echo hello"); |
| 7497 | 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().recipe.is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().()); |
| 7498 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipe.is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().()); |
| 7499 | } |
| 7500 | |
| 7501 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7502 | fn test_recipe_set_prefix_removerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_set_prefix_remove().() { |
| 7503 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\t@-echo hello\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().(); |
| 7504 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7505 | let mut recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7506 | |
| 7507 | recipe.set_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]set_prefix().(""); |
| 7508 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo hello"); |
| 7509 | 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().recipe.is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().()); |
| 7510 | 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().recipe.is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().()); |
| 7511 | } |
| 7512 | |
| 7513 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7514 | fn test_recipe_set_prefix_combinationsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_set_prefix_combinations().() { |
| 7515 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo hello\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().(); |
| 7516 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7517 | let mut recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7518 | |
| 7519 | recipe.set_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]set_prefix().("@-"); |
| 7520 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "@-echo hello"); |
| 7521 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipe.is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().()); |
| 7522 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipe.is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().()); |
| 7523 | |
| 7524 | recipe.set_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]set_prefix().("-@"); |
| 7525 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "-@echo hello"); |
| 7526 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipe.is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().()); |
| 7527 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipe.is_ignore_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_ignore_errors().()); |
| 7528 | } |
| 7529 | |
| 7530 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7531 | fn test_recipe_replace_text_basicrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_replace_text_basic().() { |
| 7532 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo hello\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().(); |
| 7533 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7534 | let mut recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7535 | |
| 7536 | recipe.replace_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]replace_text().("echo world"); |
| 7537 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo world"); |
| 7538 | |
| 7539 | // Verify it's still accessible from the rule |
| 7540 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7541 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo world"]); |
| 7542 | } |
| 7543 | |
| 7544 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7545 | fn test_recipe_replace_text_with_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_replace_text_with_prefix().() { |
| 7546 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\t@echo hello\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().(); |
| 7547 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7548 | let mut recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7549 | |
| 7550 | recipe.replace_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]replace_text().("@echo goodbye"); |
| 7551 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "@echo goodbye"); |
| 7552 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipe.is_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().()); |
| 7553 | } |
| 7554 | |
| 7555 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7556 | fn test_recipe_insert_before_singlerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_insert_before_single().() { |
| 7557 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo world\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().(); |
| 7558 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7559 | let recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7560 | |
| 7561 | recipe.insert_beforerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_before().("echo hello"); |
| 7562 | |
| 7563 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7564 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7565 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo hello", "echo world"]); |
| 7566 | } |
| 7567 | |
| 7568 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7569 | fn test_recipe_insert_before_multiplerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_insert_before_multiple().() { |
| 7570 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo one\n\techo two\n\techo three\n" |
| 7571 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 7572 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7573 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7574 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7575 | |
| 7576 | // Insert before the second recipe |
| 7577 | recipes[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()..insert_beforerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_before().("echo middle"); |
| 7578 | |
| 7579 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7580 | let new_recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7581 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7582 | new_recipes, |
| 7583 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo one", "echo middle", "echo two", "echo three"] |
| 7584 | ); |
| 7585 | } |
| 7586 | |
| 7587 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7588 | fn test_recipe_insert_before_firstrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_insert_before_first().() { |
| 7589 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo one\n\techo two\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().(); |
| 7590 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7591 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7592 | |
| 7593 | recipes[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()..insert_beforerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_before().("echo zero"); |
| 7594 | |
| 7595 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7596 | let new_recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7597 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(new_recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo zero", "echo one", "echo two"]); |
| 7598 | } |
| 7599 | |
| 7600 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7601 | fn test_recipe_insert_after_singlerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_insert_after_single().() { |
| 7602 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo hello\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().(); |
| 7603 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7604 | let recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7605 | |
| 7606 | recipe.insert_afterrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_after().("echo world"); |
| 7607 | |
| 7608 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7609 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7610 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo hello", "echo world"]); |
| 7611 | } |
| 7612 | |
| 7613 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7614 | fn test_recipe_insert_after_multiplerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_insert_after_multiple().() { |
| 7615 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo one\n\techo two\n\techo three\n" |
| 7616 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 7617 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7618 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7619 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7620 | |
| 7621 | // Insert after the second recipe |
| 7622 | recipes[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()..insert_afterrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_after().("echo middle"); |
| 7623 | |
| 7624 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7625 | let new_recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7626 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7627 | new_recipes, |
| 7628 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo one", "echo two", "echo middle", "echo three"] |
| 7629 | ); |
| 7630 | } |
| 7631 | |
| 7632 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7633 | fn test_recipe_insert_after_lastrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_insert_after_last().() { |
| 7634 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo one\n\techo two\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().(); |
| 7635 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7636 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7637 | |
| 7638 | recipes[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()..insert_afterrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_after().("echo three"); |
| 7639 | |
| 7640 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7641 | let new_recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7642 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(new_recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo one", "echo two", "echo three"]); |
| 7643 | } |
| 7644 | |
| 7645 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7646 | fn test_recipe_remove_singlerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_remove_single().() { |
| 7647 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo hello\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().(); |
| 7648 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7649 | let recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7650 | |
| 7651 | recipe.removerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]remove().(); |
| 7652 | |
| 7653 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7654 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 0); |
| 7655 | } |
| 7656 | |
| 7657 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7658 | fn test_recipe_remove_firstrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_remove_first().() { |
| 7659 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo one\n\techo two\n\techo three\n" |
| 7660 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 7661 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7662 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7663 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7664 | |
| 7665 | recipes[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()..removerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]remove().(); |
| 7666 | |
| 7667 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7668 | let new_recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7669 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(new_recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo two", "echo three"]); |
| 7670 | } |
| 7671 | |
| 7672 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7673 | fn test_recipe_remove_middlerust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_remove_middle().() { |
| 7674 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo one\n\techo two\n\techo three\n" |
| 7675 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 7676 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7677 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7678 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7679 | |
| 7680 | recipes[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()..removerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]remove().(); |
| 7681 | |
| 7682 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7683 | let new_recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7684 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(new_recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo one", "echo three"]); |
| 7685 | } |
| 7686 | |
| 7687 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7688 | fn test_recipe_remove_lastrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_remove_last().() { |
| 7689 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo one\n\techo two\n\techo three\n" |
| 7690 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 7691 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7692 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7693 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7694 | |
| 7695 | recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..removerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]remove().(); |
| 7696 | |
| 7697 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7698 | let new_recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7699 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(new_recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo one", "echo two"]); |
| 7700 | } |
| 7701 | |
| 7702 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7703 | fn test_recipe_multiple_operationsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_multiple_operations().() { |
| 7704 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo one\n\techo two\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().(); |
| 7705 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7706 | let mut recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7707 | |
| 7708 | // Replace text |
| 7709 | recipe.replace_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]replace_text().("echo modified"); |
| 7710 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo modified"); |
| 7711 | |
| 7712 | // Add prefix |
| 7713 | recipe.set_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]set_prefix().("@"); |
| 7714 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "@echo modified"); |
| 7715 | |
| 7716 | // Insert after |
| 7717 | recipe.insert_afterrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]insert_after().("echo three"); |
| 7718 | |
| 7719 | // Verify all changes |
| 7720 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7721 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7722 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["@echo modified", "echo three", "echo two"]); |
| 7723 | } |
| 7724 | |
| 7725 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7726 | fn test_from_str_relaxed_validrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_from_str_relaxed_valid().() { |
| 7727 | let input = "all: foo\n\tfoo bar\n"; |
| 7728 | let (makefile, errors) = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_str_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_str_relaxed().(input); |
| 7729 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(errors.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 7730 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 7731 | 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().(), input); |
| 7732 | } |
| 7733 | |
| 7734 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7735 | fn test_from_str_relaxed_with_errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_from_str_relaxed_with_errors().() { |
| 7736 | // "rule target\n\tcommand" produces a parse error (missing colon) |
| 7737 | let input = "rule target\n\tcommand\n"; |
| 7738 | let (makefile, errors) = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_str_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_str_relaxed().(input); |
| 7739 | 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().errors.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 7740 | // Round-trip preserves all text |
| 7741 | 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().(), input); |
| 7742 | } |
| 7743 | |
| 7744 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7745 | fn test_positioned_errors_have_valid_rangesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_positioned_errors_have_valid_ranges().() { |
| 7746 | let input = "rule target\n\tcommand\n"; |
| 7747 | let parsed = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::parserust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]parse().(input); |
| 7748 | 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().parsed.okrust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]ok().()); |
| 7749 | |
| 7750 | let positioned = parsed.positioned_errorsrust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]positioned_errors().(); |
| 7751 | 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().positioned.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()); |
| 7752 | |
| 7753 | for err in positioned { |
| 7754 | // Range should be within the input |
| 7755 | let start: u32 = err.rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#range..startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 7756 | let end: u32 = err.rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#range..endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 7757 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(start <= end); |
| 7758 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!((end as usize) <= input.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()); |
| 7759 | } |
| 7760 | } |
| 7761 | |
| 7762 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7763 | fn test_positioned_errors_point_to_error_locationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_positioned_errors_point_to_error_location().() { |
| 7764 | let input = "rule target\n\tcommand\n"; |
| 7765 | let parsed = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::parserust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]parse().(input); |
| 7766 | 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().parsed.okrust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]ok().()); |
| 7767 | |
| 7768 | let positioned = parsed.positioned_errorsrust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]positioned_errors().(); |
| 7769 | 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().positioned.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()); |
| 7770 | |
| 7771 | let err = &positioned[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 7772 | let start: usize = err.rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#range..startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 7773 | let end: usize = err.rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#range..endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 7774 | // The error should point somewhere in the input |
| 7775 | let error_text = &input[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 7776 | 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().error_text.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().()); |
| 7777 | |
| 7778 | // Tree should still be accessible |
| 7779 | let tree = parsed.treerust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]tree().(); |
| 7780 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(tree.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), input); |
| 7781 | } |
| 7782 | |
| 7783 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7784 | fn test_tree_with_errors_preserves_textrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_tree_with_errors_preserves_text().() { |
| 7785 | let input = "rule target\n\tcommand\nVAR = value\n"; |
| 7786 | let parsed = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::parserust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]parse().(input); |
| 7787 | 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().parsed.okrust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]ok().()); |
| 7788 | |
| 7789 | let tree = parsed.treerust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]tree().(); |
| 7790 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(tree.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), input); |
| 7791 | |
| 7792 | // Valid parts should still be accessible |
| 7793 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(tree.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 1); |
| 7794 | } |
| 7795 | |
| 7796 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7797 | fn test_recipe_variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_variable_references().() { |
| 7798 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo $(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().(); |
| 7799 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7800 | let recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7801 | let refs = recipe.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]variable_references().(); |
| 7802 | let names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = refs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]name().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7803 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(names, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["FOO", "BAR"]); |
| 7804 | |
| 7805 | // Ranges point at the variable names in the original source. |
| 7806 | let src = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 7807 | for r in &refs { |
| 7808 | let range = r.text_rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]text_range().(); |
| 7809 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&src[rust-analyzer cargo text-size 1.1.1 range/impl#[String][`Index<TextRange>`]index().range]rust-analyzer cargo text-size 1.1.1 range/impl#[String][`Index<TextRange>`]index()., r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]name().()); |
| 7810 | } |
| 7811 | } |
| 7812 | |
| 7813 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7814 | fn test_recipe_variable_references_skips_functions_and_automaticrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_variable_references_skips_functions_and_automatic().() { |
| 7815 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\t$(shell ls) $@ $1 $(REAL)\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().(); |
| 7816 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7817 | let recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7818 | let names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = recipe |
| 7819 | .variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]variable_references().() |
| 7820 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 7821 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]name().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 7822 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7823 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(names, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["REAL"]); |
| 7824 | } |
| 7825 | |
| 7826 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7827 | fn test_recipe_variable_references_across_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/tests/test_recipe_variable_references_across_continuation().() { |
| 7828 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all:\n\techo $(FOO) \\\n\t $(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().(); |
| 7829 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7830 | let recipe = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().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().(); |
| 7831 | let refs = recipe.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]variable_references().(); |
| 7832 | let names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = refs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]name().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7833 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(names, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["FOO", "BAR"]); |
| 7834 | |
| 7835 | let src = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 7836 | for r in &refs { |
| 7837 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&src[rust-analyzer cargo text-size 1.1.1 range/impl#[String][`Index<TextRange>`]index().r.text_rangerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]text_range().()]rust-analyzer cargo text-size 1.1.1 range/impl#[String][`Index<TextRange>`]index()., r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[RecipeVariableReference]name().()); |
| 7838 | } |
| 7839 | } |
| 7840 | } |
| 7841 | |
| 7842 | #[cfg(test)] |
| 7843 | mod test_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/ { |
| 7844 | use superrust-analyzer cargo makefile-lossless 0.3.40 lossless/::*; |
| 7845 | |
| 7846 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7847 | fn test_recipe_continuation_linesrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_recipe_continuation_lines().() { |
| 7848 | let makefile_content = r#"override_dh_autoreconf: |
| 7849 | set -x; [ -f binoculars-ng/src/Hkl/H5.hs.orig ] || \ |
| 7850 | dpkg --compare-versions '$(HDF5_VERSION)' '<<' 1.12.0 || \ |
| 7851 | sed -i.orig 's/H5L_info_t/H5L_info1_t/g;s/h5l_iterate/h5l_iterate1/g' binoculars-ng/src/Hkl/H5.hs |
| 7852 | dh_autoreconf |
| 7853 | "#; |
| 7854 | |
| 7855 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7856 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7857 | |
| 7858 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7859 | |
| 7860 | // Should have 2 recipe nodes: one multi-line command and one single-line |
| 7861 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 7862 | |
| 7863 | // First recipe should contain all three physical lines with newlines preserved, |
| 7864 | // and the leading tab stripped from each continuation line |
| 7865 | let expected_first = "set -x; [ -f binoculars-ng/src/Hkl/H5.hs.orig ] || \\\n dpkg --compare-versions '$(HDF5_VERSION)' '<<' 1.12.0 || \\\n sed -i.orig 's/H5L_info_t/H5L_info1_t/g;s/h5l_iterate/h5l_iterate1/g' binoculars-ng/src/Hkl/H5.hs"; |
| 7866 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), expected_first); |
| 7867 | |
| 7868 | // Second recipe should be the standalone dh_autoreconf line |
| 7869 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "dh_autoreconf"); |
| 7870 | } |
| 7871 | |
| 7872 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7873 | fn test_simple_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_simple_continuation().() { |
| 7874 | let makefile_content = "test:\n\techo hello && \\\n\t echo world\n"; |
| 7875 | |
| 7876 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7877 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7878 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7879 | |
| 7880 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7881 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo hello && \\\n echo world"); |
| 7882 | } |
| 7883 | |
| 7884 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7885 | fn test_multiple_continuationsrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_multiple_continuations().() { |
| 7886 | let makefile_content = "test:\n\techo line1 && \\\n\t echo line2 && \\\n\t echo line3 && \\\n\t echo line4\n"; |
| 7887 | |
| 7888 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7889 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7890 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7891 | |
| 7892 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7893 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7894 | recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), |
| 7895 | "echo line1 && \\\n echo line2 && \\\n echo line3 && \\\n echo line4" |
| 7896 | ); |
| 7897 | } |
| 7898 | |
| 7899 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7900 | fn test_continuation_round_triprust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_continuation_round_trip().() { |
| 7901 | let makefile_content = "test:\n\techo hello && \\\n\t echo world\n\techo done\n"; |
| 7902 | |
| 7903 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7904 | let output = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 7905 | |
| 7906 | // Should preserve the exact content |
| 7907 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, makefile_content); |
| 7908 | } |
| 7909 | |
| 7910 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7911 | fn test_continuation_with_silent_prefixrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_continuation_with_silent_prefix().() { |
| 7912 | let makefile_content = "test:\n\t@echo hello && \\\n\t echo world\n"; |
| 7913 | |
| 7914 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7915 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7916 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7917 | |
| 7918 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 7919 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "@echo hello && \\\n echo world"); |
| 7920 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(recipes[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_silentrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]is_silent().()); |
| 7921 | } |
| 7922 | |
| 7923 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7924 | fn test_mixed_continued_and_non_continuedrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_mixed_continued_and_non_continued().() { |
| 7925 | let makefile_content = r#"test: |
| 7926 | echo first |
| 7927 | echo second && \ |
| 7928 | echo third |
| 7929 | echo fourth |
| 7930 | "#; |
| 7931 | |
| 7932 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7933 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7934 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7935 | |
| 7936 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3); |
| 7937 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo first"); |
| 7938 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo second && \\\n echo third"); |
| 7939 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo fourth"); |
| 7940 | } |
| 7941 | |
| 7942 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7943 | fn test_continuation_replace_commandrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_continuation_replace_command().() { |
| 7944 | let makefile_content = "test:\n\techo hello && \\\n\t echo world\n\techo done\n"; |
| 7945 | |
| 7946 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7947 | let mut rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7948 | |
| 7949 | // Replace the multi-line command |
| 7950 | rule.replace_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]replace_command().(0, "echo replaced"); |
| 7951 | |
| 7952 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7953 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 7954 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo replaced"); |
| 7955 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo done"); |
| 7956 | } |
| 7957 | |
| 7958 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7959 | fn test_continuation_countrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_continuation_count().() { |
| 7960 | let makefile_content = "test:\n\techo hello && \\\n\t echo world\n\techo done\n"; |
| 7961 | |
| 7962 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7963 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7964 | |
| 7965 | // Even though there are 3 physical lines, there should be 2 logical recipe nodes |
| 7966 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 2); |
| 7967 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().(), 2); |
| 7968 | |
| 7969 | // recipes() should return one string per logical recipe node |
| 7970 | let recipes_list: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7971 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 7972 | recipes_list, |
| 7973 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["echo hello && \\\n echo world", "echo done"] |
| 7974 | ); |
| 7975 | } |
| 7976 | |
| 7977 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7978 | fn test_backslash_in_middle_of_linerust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_backslash_in_middle_of_line().() { |
| 7979 | // Backslash not at end should not trigger continuation |
| 7980 | let makefile_content = "test:\n\techo hello\\nworld\n\techo done\n"; |
| 7981 | |
| 7982 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 7983 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 7984 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 7985 | |
| 7986 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 7987 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo hello\\nworld"); |
| 7988 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(), "echo done"); |
| 7989 | } |
| 7990 | |
| 7991 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 7992 | fn test_shell_for_loop_with_continuationrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_shell_for_loop_with_continuation().() { |
| 7993 | // Regression test for Debian bug #1128608 / GitHub issue (if any) |
| 7994 | // Ensures shell for loops with backslash continuations are treated as |
| 7995 | // a single recipe node and preserve the 'done' statement |
| 7996 | let makefile_content = r#"override_dh_installman: |
| 7997 | for i in foo bar; do \ |
| 7998 | pod2man --section=1 $$i ; \ |
| 7999 | done |
| 8000 | "#; |
| 8001 | |
| 8002 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 8003 | let rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 8004 | |
| 8005 | // Should have exactly 1 recipe node containing the entire for loop |
| 8006 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8007 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8008 | |
| 8009 | // The recipe text should contain the complete for loop including 'done' |
| 8010 | let recipe_text = recipes[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()..textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().(); |
| 8011 | let expected_recipe = "for i in foo bar; do \\\n\tpod2man --section=1 $$i ; \\\ndone"; |
| 8012 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipe_text, expected_recipe); |
| 8013 | |
| 8014 | // Round-trip should preserve the complete structure |
| 8015 | let output = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 8016 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, makefile_content); |
| 8017 | } |
| 8018 | |
| 8019 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8020 | fn test_shell_for_loop_remove_commandrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_shell_for_loop_remove_command().() { |
| 8021 | // Regression test: removing other commands shouldn't affect 'done' |
| 8022 | // This simulates lintian-brush modifying debian/rules files |
| 8023 | let makefile_content = r#"override_dh_installman: |
| 8024 | for i in foo bar; do \ |
| 8025 | pod2man --section=1 $$i ; \ |
| 8026 | done |
| 8027 | echo "Done with man pages" |
| 8028 | "#; |
| 8029 | |
| 8030 | let makefile = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().(makefile_content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 8031 | let mut rule = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().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().(); |
| 8032 | |
| 8033 | // Should have 2 recipe nodes: the for loop and the echo |
| 8034 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rule.recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(), 2); |
| 8035 | |
| 8036 | // Remove the second command (the echo) |
| 8037 | rule.remove_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_command().(1); |
| 8038 | |
| 8039 | // Should now have only the for loop |
| 8040 | let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = rule.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8041 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8042 | |
| 8043 | // The for loop should still be complete with 'done' |
| 8044 | let output = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 8045 | let expected_output = r#"override_dh_installman: |
| 8046 | for i in foo bar; do \ |
| 8047 | pod2man --section=1 $$i ; \ |
| 8048 | done |
| 8049 | "#; |
| 8050 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, expected_output); |
| 8051 | } |
| 8052 | |
| 8053 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8054 | fn test_variable_reference_parenrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_variable_reference_paren().() { |
| 8055 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = $(BASE_FLAGS) -Wall\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().(); |
| 8056 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8057 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8058 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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 lossless/impl#[VariableReference]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("BASE_FLAGS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8059 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "$(BASE_FLAGS)"); |
| 8060 | } |
| 8061 | |
| 8062 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8063 | fn test_variable_reference_bracerust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_variable_reference_brace().() { |
| 8064 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = ${BASE_FLAGS} -Wall\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().(); |
| 8065 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8066 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8067 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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 lossless/impl#[VariableReference]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("BASE_FLAGS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8068 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "${BASE_FLAGS}"); |
| 8069 | } |
| 8070 | |
| 8071 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8072 | fn test_variable_reference_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_variable_reference_in_prerequisites().() { |
| 8073 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all: $(TARGETS)\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().(); |
| 8074 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8075 | let names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = refs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|r| r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]name().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8076 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"TARGETS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8077 | } |
| 8078 | |
| 8079 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8080 | fn test_variable_reference_multiplerust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_variable_reference_multiple().() { |
| 8081 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = |
| 8082 | "CFLAGS = $(BASE_FLAGS) -Wall\nLDFLAGS = $(BASE_LDFLAGS) -lm\nall: $(TARGETS)\n" |
| 8083 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 8084 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 8085 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8086 | let names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = refs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|r| r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]name().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8087 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"BASE_FLAGS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8088 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"BASE_LDFLAGS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8089 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"TARGETS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8090 | } |
| 8091 | |
| 8092 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8093 | fn test_variable_reference_nestedrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_variable_reference_nested().() { |
| 8094 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "FOO = $($(INNER))\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().(); |
| 8095 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8096 | let names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = refs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|r| r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]name().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8097 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"INNER".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8098 | } |
| 8099 | |
| 8100 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8101 | fn test_variable_reference_line_colrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_variable_reference_line_col().() { |
| 8102 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "A = 1\nB = $(FOO)\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().(); |
| 8103 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8104 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8105 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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 lossless/impl#[VariableReference]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().())); |
| 8106 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..linerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]line().(), 1); |
| 8107 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..columnrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]column().(), 4); |
| 8108 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..line_colrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]line_col().(), (1, 4)); |
| 8109 | } |
| 8110 | |
| 8111 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8112 | fn test_variable_reference_no_refsrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_variable_reference_no_refs().() { |
| 8113 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "A = hello\nall:\n\techo done\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().(); |
| 8114 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8115 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0); |
| 8116 | } |
| 8117 | |
| 8118 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8119 | fn test_variable_reference_mixed_stylesrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_variable_reference_mixed_styles().() { |
| 8120 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "A = $(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().(); |
| 8121 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8122 | let names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = refs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|r| r.namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]name().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8123 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(names.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 8124 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"FOO".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8125 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&"BAR".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8126 | } |
| 8127 | |
| 8128 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8129 | fn test_brace_variable_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_brace_variable_in_prerequisites().() { |
| 8130 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "all: ${OBJS}\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().(); |
| 8131 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8132 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8133 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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 lossless/impl#[VariableReference]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("OBJS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 8134 | } |
| 8135 | |
| 8136 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8137 | fn test_parse_brace_variable_roundtriprust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_parse_brace_variable_roundtrip().() { |
| 8138 | let input = "CFLAGS = ${BASE_FLAGS} -Wall\n"; |
| 8139 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.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().(); |
| 8140 | 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().(), input); |
| 8141 | } |
| 8142 | |
| 8143 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8144 | fn test_parse_nested_variable_in_value_roundtriprust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_parse_nested_variable_in_value_roundtrip().() { |
| 8145 | let input = "FOO = $(BAR) baz $(QUUX)\n"; |
| 8146 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.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().(); |
| 8147 | 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().(), input); |
| 8148 | } |
| 8149 | |
| 8150 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8151 | fn test_is_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_is_function_call().() { |
| 8152 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "FILES = $(wildcard *.c)\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().(); |
| 8153 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8154 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8155 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(refs[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_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]is_function_call().()); |
| 8156 | } |
| 8157 | |
| 8158 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8159 | fn test_is_function_call_simple_variablerust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_is_function_call_simple_variable().() { |
| 8160 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = $(CC)\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().(); |
| 8161 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8162 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8163 | 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().refs[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_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]is_function_call().()); |
| 8164 | } |
| 8165 | |
| 8166 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8167 | fn test_is_function_call_with_commasrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_is_function_call_with_commas().() { |
| 8168 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "X = $(subst a,b,text)\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().(); |
| 8169 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8170 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8171 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(refs[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_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]is_function_call().()); |
| 8172 | } |
| 8173 | |
| 8174 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8175 | fn test_is_function_call_bracesrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_is_function_call_braces().() { |
| 8176 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "FILES = ${wildcard *.c}\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().(); |
| 8177 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8178 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 8179 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(refs[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_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]is_function_call().()); |
| 8180 | } |
| 8181 | |
| 8182 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8183 | fn test_argument_count_simple_variablerust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_argument_count_simple_variable().() { |
| 8184 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = $(CC)\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().(); |
| 8185 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8186 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_countrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_count().(), 0); |
| 8187 | } |
| 8188 | |
| 8189 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8190 | fn test_argument_count_one_argrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_argument_count_one_arg().() { |
| 8191 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "FILES = $(wildcard *.c)\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().(); |
| 8192 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8193 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_countrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_count().(), 1); |
| 8194 | } |
| 8195 | |
| 8196 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8197 | fn test_argument_count_three_argsrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_argument_count_three_args().() { |
| 8198 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "X = $(subst a,b,text)\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().(); |
| 8199 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8200 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_countrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_count().(), 3); |
| 8201 | } |
| 8202 | |
| 8203 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8204 | fn test_argument_index_at_offset_substrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_argument_index_at_offset_subst().() { |
| 8205 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "X = $(subst a,b,text)\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().(); |
| 8206 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8207 | // "X = $(subst a,b,text)" |
| 8208 | // 0123456789012345678901 |
| 8209 | // ^first arg (offset 12) |
| 8210 | // ^second arg (offset 14) |
| 8211 | // ^third arg (offset 16) |
| 8212 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_index_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_index_at_offset().(12), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)); |
| 8213 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_index_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_index_at_offset().(14), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)); |
| 8214 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_index_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_index_at_offset().(16), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2)); |
| 8215 | } |
| 8216 | |
| 8217 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8218 | fn test_argument_index_at_offset_outsiderust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_argument_index_at_offset_outside().() { |
| 8219 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "X = $(subst a,b,text)\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().(); |
| 8220 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8221 | // Before the reference |
| 8222 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_index_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_index_at_offset().(0), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 8223 | // After the reference |
| 8224 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_index_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_index_at_offset().(22), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 8225 | } |
| 8226 | |
| 8227 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8228 | fn test_argument_index_at_offset_simple_variablerust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_argument_index_at_offset_simple_variable().() { |
| 8229 | let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "CFLAGS = $(CC)\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().(); |
| 8230 | let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8231 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[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()..argument_index_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]argument_index_at_offset().(11), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 8232 | } |
| 8233 | |
| 8234 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8235 | fn test_lex_bracesrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_lex_braces().() { |
| 8236 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::lexrust-analyzer cargo makefile-lossless 0.3.40 lex/::lexrust-analyzer cargo makefile-lossless 0.3.40 lex/lex().; |
| 8237 | let tokens = lexrust-analyzer cargo makefile-lossless 0.3.40 lex/lex().("${FOO}"); |
| 8238 | let kinds: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = tokens.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(k, _)| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 8239 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(kinds.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#)); |
| 8240 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(kinds.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&LBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LBRACE#)); |
| 8241 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(kinds.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&RBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RBRACE#)); |
| 8242 | } |
| 8243 | |
| 8244 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8245 | fn test_parse_quoted_string_inside_function_callrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_parse_quoted_string_inside_function_call().() { |
| 8246 | // The lexer emits a balanced quoted string as one QUOTE token, so a |
| 8247 | // quoted argument with embedded parentheses must not break paren |
| 8248 | // balance tracking inside a $(...) expression. Lone or asymmetric |
| 8249 | // quotes (it's, foo'bar) must not swallow the rest of the line. |
| 8250 | let cases = [ |
| 8251 | "X = $(if a,'foo')\n", |
| 8252 | "X = $(if a,'foo (bar)')\n", |
| 8253 | "X = $(if a,'(')\n", |
| 8254 | "X = $(if a,')')\n", |
| 8255 | "X = $(if $(SKIP),-k 'not ($(call f,$(s),$(SKIP)))')\n", |
| 8256 | "X = foo'bar\nY = baz\n", |
| 8257 | "X = it's fine\n", |
| 8258 | "X = $(if a,it's)\n", |
| 8259 | "X = '\nY = bar\n", |
| 8260 | ]; |
| 8261 | for src in cases { |
| 8262 | let parsed: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = src.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|e| { |
| 8263 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("failed to parse {src:?}: {e:?}"); |
| 8264 | }); |
| 8265 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parsed.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), src, "round-trip mismatch for {src:?}"); |
| 8266 | } |
| 8267 | } |
| 8268 | |
| 8269 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8270 | fn test_parse_unclosed_conditional_paren_does_not_panicrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_parse_unclosed_conditional_paren_does_not_panic().() { |
| 8271 | // Found by cargo-fuzz: nested LPAREN inside ifeq()/ifneq() opened |
| 8272 | // an EXPR node that was only closed by the matching RPAREN. EOF |
| 8273 | // before the close left the green tree unbalanced and rowan |
| 8274 | // panicked in GreenNodeBuilder::finish. |
| 8275 | let cases = ["ifeq((", "ifeq(((((", "ifneq((", "ifeq(($(X)", "X = $(("]; |
| 8276 | for src in cases { |
| 8277 | let parse = craterust-analyzer cargo makefile-lossless 0.3.40 crate/::parserust-analyzer cargo makefile-lossless 0.3.40 parse/::Parserust-analyzer cargo makefile-lossless 0.3.40 parse/Parse#::<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#>::parse_makefilerust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<Makefile>`]parse_makefile().(src); |
| 8278 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 8279 | parse.treerust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]tree().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 8280 | src, |
| 8281 | "round-trip mismatch for {src:?}" |
| 8282 | ); |
| 8283 | } |
| 8284 | } |
| 8285 | |
| 8286 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 8287 | fn test_parse_unexpected_tokens_at_top_level_does_not_panicrust-analyzer cargo makefile-lossless 0.3.40 lossless/test_continuation/test_parse_unexpected_tokens_at_top_level_does_not_panic().() { |
| 8288 | // Found by cargo-fuzz: the top-level dispatcher's catch-all arm |
| 8289 | // bumped a token after `error()` had already consumed one, which |
| 8290 | // could pop past the end of the token stack. The parser must |
| 8291 | // tolerate arbitrary garbage without panicking, and the lossless |
| 8292 | // round-trip must still hold. |
| 8293 | let cases = ["(", "(\0(", ")", "(())", "\0", ",", ":", "((((((((((("]; |
| 8294 | for src in cases { |
| 8295 | let parse = craterust-analyzer cargo makefile-lossless 0.3.40 crate/::parserust-analyzer cargo makefile-lossless 0.3.40 parse/::Parserust-analyzer cargo makefile-lossless 0.3.40 parse/Parse#::<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#>::parse_makefilerust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<Makefile>`]parse_makefile().(src); |
| 8296 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 8297 | parse.treerust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<T>`]tree().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 8298 | src, |
| 8299 | "round-trip mismatch for {src:?}" |
| 8300 | ); |
| 8301 | } |
| 8302 | } |
| 8303 | } |