Macro Newbie Q: for testing, how to deal with different indentation?

I'm following along with WWDC Write Swift Macros.

I use 2 spaces for indent, however, this seems to mess with assertMacroExpansion:

 enum EasySlope {
   case beginnersParadise
   case practiceRun
–  init?(_ slope: Slope) {
–    switch slope {
–    case .beginnersParadise:
–      self = .beginnerParadise
–    case .practiceRun:
–      self = .practiceRun
–    default:
–      return nil
+
+    init?(_ slope: Slope) {
+        switch slope {
+        case .beginnersParadise:
+          self = .beginnersParadise
+        case .practiceRun:
+          self = .practiceRun
+        default:
+            return nil
+        }
     }
–  }
 }

Actual expanded source:

enum EasySlope {
  case beginnersParadise
  case practiceRun

    init?(_ slope: Slope) {
        switch slope {
        case .beginnersParadise:
          self = .beginnersParadise
        case .practiceRun:
          self = .practiceRun
        default:
            return nil
        }
    }
}

how to deal with this 2 spaces 4 spaces indentation difference?
also whole init block is indented an extra level?

is there a way to assert the syntax tree indeed of textual comparison, which is prone is miss spelling and space indentation conflicts.

1 Like

assertMacroExpansion does accept argument for indentation value with label indentationWidth, you can pass .spaces(2) for indentation with 2 spaces.

2 Likes