package linthost

import (
  "os"
  "path/filepath"
  "testing"
)

// TestFormatBraceContinuationPushesPastALabelPrefix verifies a labeled statement
// still pushes its continuation keyword down.
//
// The abstention for a statement that does not own its line is what keeps a
// keyword from landing at column zero. The supported ASCII `outer:` prefix
// belongs to the labeled statement; the helper accepts that label run when
// locating its owning indentation. This command fixture requires the label to
// remain on the if line and observes the completed cascade for this input,
// without a claim about every label or every hypothetical deferred pass.
//
//  1. Seed a project with a labeled one-line `if`/`else` inside a function.
//  2. Run `ttsc format`.
//  3. Assert `else` lands on its own line at the statement's column.
//
// @evidence contracts/testing.md#behavioral-verification The in-process format command must complete the cascade for a labeled if/else and place else at the two-space column while retaining outer: on the if line.
// @evidence contracts/testing.md#independent-expectations The fixed full-file literal preserves the label, function, condition and calls; zero exit code and empty stdout/stderr independently require a successful quiet command as well as correct disk content.
// @evidence contracts/testing.md#distinguishing-cases This labeled-prefix command positive distinguishes a label belonging to the same statement from a preceding statement requiring deferral; the shared-line cascade and direct abstention cases own that neighboring decision.
// @evidence contracts/testing.md#execution-ownership TestFormatBraceContinuationPushesPastALabelPrefix is a public Go unit selected by the lint semantic-unit Evidence claim. This host owns the seeded project/config fixtures and all exit, stream and full disk-output assertions. It calls the real formatter command and cascade in the same Go process; no consumer install, native product build or product host is started.
func TestFormatBraceContinuationPushesPastALabelPrefix(t *testing.T) {
  root := seedLintProject(t, "function f() {\n  outer: if (a) x(); else y();\n}\n")
  seedLintConfig(t, root, map[string]any{"format": map[string]any{}})
  code, stdout, stderr := captureCommandOutput(t, func() int {
    return run([]string{
      "format",
      "--cwd", root,
      "--plugins-json", lintManifest(t),
    })
  })
  if code != 0 || stdout != "" || stderr != "" {
    t.Fatalf("format command mismatch: code=%d stdout=%q stderr=%q", code, stdout, stderr)
  }
  got, err := os.ReadFile(filepath.Join(root, "src", "main.ts"))
  if err != nil {
    t.Fatalf("ReadFile: %v", err)
  }
  want := "function f() {\n  outer: if (a) x();\n  else y();\n}\n"
  if string(got) != want {
    t.Fatalf("formatted source mismatch:\nwant %q\ngot  %q", want, string(got))
  }
}
