1package sheet23import "testing"45// Linked files and sent outputs are one set: a formula names either as6// nu.name, and their names are one namespace.7func TestLinkedAmongRegions(t *testing.T) {8 s := New()9 w := s.Book()10 id, err := s.AddLinked(Addr{}, LinkSource{Path: "logs/app-2026.csv"})11 if err != nil || id != "app_2026" {12 t.Fatalf("name %q, %v", id, err)13 }14 apply(t, s, LiveOp{Region: id, Reset: true, Header: liveRow("n"), Rows: []LiveRow{liveRow("2"), liveRow("3")}})15 sent(t, s, "r1", "D1")16 other, _ := w.AddSheet("Sheet2", 2)17 other.Set(Addr{}, "=SUM(nu.app_2026)")18 if v := other.Value(Addr{}).Num; v != 5 {19 t.Fatalf("SUM(nu.app_2026) = %v", other.Value(Addr{}))20 }21 apply(t, s, LiveOp{Region: id, Rows: []LiveRow{liveRow("4")}})22 if v := other.Value(Addr{}).Num; v != 9 {23 t.Fatalf("after a row arrived, SUM = %v", v)24 }25 if got := w.linkName("logs/app-2026.csv"); got != "app_2026_2" {26 t.Errorf("a second link to the file is named %q", got)27 }28 if got := w.linkName("9.csv"); got != "file_9" {29 t.Errorf("a file named 9 is %q", got)30 }31 if got := w.linkName("r1.csv"); got != "r1_2" {32 t.Errorf("a file named like a cell is %q", got)33 }34 if len(w.LinkedRegions()) != 1 {35 t.Errorf("linked regions %+v", w.LinkedRegions())36 }37}3839// Rows arriving are never undo steps, for either kind.40func TestRegionKindsUndo(t *testing.T) {41 s := New()42 id, _ := s.AddLinked(Addr{}, LinkSource{Path: "log.csv"})43 apply(t, s, LiveOp{Region: id, Reset: true, Header: liveRow("n"), Rows: []LiveRow{liveRow("1")}})44 if s.Book().UndoLabel() != "add log" {45 t.Errorf("rows arriving made a step: %q", s.Book().UndoLabel())46 }47 sent(t, s, "r1", "D1")48 apply(t, s, LiveOp{Region: "r1", Reset: true, Header: liveRow("n"), Rows: []LiveRow{liveRow("7")}})49 if s.Book().UndoLabel() != "add r1" {50 t.Errorf("an output arriving made a step: %q", s.Book().UndoLabel())51 }52 s.Book().Undo()53 wantShown(t, s, map[string]string{"D1": "", "D2": "", "A2": "1"})54}