oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1package guards
2
3import (
4 "testing"
5)
6
7// calcHome is the formula engine's package tree — calc itself and any
8// subpackage of it (e.g. a future calc/functions).
9const calcHome = "internal/sheets/calc"
10
11// storeImport is the storage layer's own import path. Matched as a tree
12// (storeImport itself, or anything nested under it, e.g. a hypothetical
13// future store/schema) so a subpackage of store can't quietly slip past
14// an exact-equality check the way store's root package can't today.
15const storeImport = "amadan.net/oficina/sheets/internal/sheets/store"
16
17// sheetsImport is internal/sheets itself — the app/wiring package, not
18// its namespace. Deliberately matched by exact equality, not as a tree:
19// internal/sheets/format, /xlsx, /seal, /sealtest and /guards all live
20// under that same import prefix, and the rule as written ("internal/sheets
21// itself") names the one package, not everything nested under it. Widening
22// this to a tree match would silently forbid calc from importing any of
23// those siblings too — a real rule change, not a blind-spot fix, and one
24// nobody has decided to make.
25const sheetsImport = "amadan.net/oficina/sheets/internal/sheets"
26
27// TestCalcIsolatedFromStoreAndSheets fails on any file in the
28// internal/sheets/calc tree that imports the store package (or any
29// future subpackage of it) or internal/sheets itself.
30func TestCalcIsolatedFromStoreAndSheets(t *testing.T) {
31 root := repoRoot(t)
32 for _, path := range goFiles(t, root) {
33 rel := relPath(t, root, path)
34 if !inTree(rel, calcHome) {
35 continue
36 }
37 for _, imp := range fileImports(t, path) {
38 switch {
39 case importUnder(imp, storeImport):
40 t.Errorf("%s: imports %q, forbidden in %s (calc isolation)", rel, imp, calcHome)
41 case imp == sheetsImport:
42 t.Errorf("%s: imports %q, forbidden in %s (calc isolation)", rel, imp, calcHome)
43 }
44 }
45 }
46}
47