Skip to content
quarry Artifact [9af1657824]
Login

Artifact [9af1657824]

Artifact 9af1657824ab52b0a8c51050d791d0b677a894b7f1e3f79877f52dabf046a1db:


package web

import (
	"encoding/json"
	"strings"
	"testing"
)

// #381: a stack whose middle rung conflicts lands the rungs below it,
// and the strip says so instead of "nothing in this stack lands".
func TestAStoppedStackSaysWhatLandingLands(t *testing.T) {
	render := func(landCount int) string {
		var stack stackView
		if err := json.Unmarshal([]byte(`{"segments":[
			{"id":"r1aaaaaaaaaa","number":1,"position":1,"state":"open"},
			{"id":"r2aaaaaaaaaa","number":2,"position":2,"state":"open","preflight":"conflict","preflightConflicts":["s2.txt"]},
			{"id":"r3aaaaaaaaaa","number":3,"position":3,"state":"open"}],
			"preflight":"stops","stopsAt":2,"landTo":"r1aaaaaaaaaa","landCount":`+itoa(landCount)+`}`), &stack); err != nil {
			t.Fatal(err)
		}
		var buf strings.Builder
		if err := noHooks.template(landingPage).ExecuteTemplate(&buf, "landing-body", pageData{Repo: "quarry",
			Landing: &landingDetail{landingRow: landingRow{ID: "r3aaaaaaaaaa", Branch: "s3", Target: "s2", State: "open"},
				Position: 3, Stack: stack}}); err != nil {
			t.Fatal(err)
		}
		return buf.String()
	}
	got := render(1)
	if !strings.Contains(got, `data-hook="stack-stops-lands" data-count="1"`) || strings.Contains(got, "Nothing in this stack lands") {
		t.Error("FAIL: a stack that lands its bottom rung says nothing in it lands")
	}
	if got := render(0); !strings.Contains(got, `data-hook="stack-stops-lands" data-count="0"`) {
		t.Error("FAIL: a stack stopped at its base does not say nothing lands")
	}
}

// #382: a comment shown as text decodes its character references, as
// the body does, and the page escapes it once.
func TestCommentTextDecodesCharacterReferences(t *testing.T) {
	if got := commentText("0.0&lt;B&lt;1.0 and AT&amp;T &#8212; [/wiki?name=X | a &amp; b]"); got != "0.0<B<1.0 and AT&T — a & b" {
		t.Errorf("FAIL: commentText = %q", got)
	}
}