shithub: mycel

Download patch

ref: 4c8c0104cf491d9d9ccdc9f7d020507fe37c26bd
parent: aba2176b2725ae502e7f4230bc5c5abad0cddea8
author: Philip Silva <[email protected]>
date: Thu Jan 21 14:28:42 EST 2021

test for Arrange(..)

--- a/browser/browser_test.go
+++ b/browser/browser_test.go
@@ -5,6 +5,7 @@
 	"golang.org/x/net/html"
 	"net/http"
 	"net/url"
+	"github.com/chris-ramon/douceur/css"
 	"github.com/psilva261/opossum/logger"
 	"github.com/psilva261/opossum/nodes"
 	"github.com/psilva261/opossum/style"
@@ -25,6 +26,63 @@
 	orig   string
 	href   string
 	expect string
+}
+
+func TestArrange(t *testing.T) {
+	htm := `
+		<div>
+			<h1>title 1</h1>
+			<h2>title 2</h2>
+			<h3>title 3</h3>
+		</div>
+	`
+	for _, d := range []string{"inline", "block"} {
+		doc, err := html.ParseWithOptions(
+			strings.NewReader(string(htm)),
+			html.ParseOptionEnableScripting(false),
+		)
+		if err != nil {
+			t.Fatalf(err.Error())
+		}
+		nodeMap := make(map[*html.Node]style.Map)
+		nt := nodes.NewNodeTree(doc, style.Map{}, nodeMap, nil)
+		h1 := nt.Find("h1")
+		h2 := nt.Find("h2")
+		h3 := nt.Find("h3")
+
+		m := style.Map{
+			Declarations: make(map[string]css.Declaration),
+		}
+		m.Declarations["display"] = css.Declaration{
+			Property: "display",
+			Value:    d,
+		}
+		h1.Map = m
+		h2.Map = m
+		h3.Map = m
+
+		es := []*Element{
+			&Element{n: h1},
+			&Element{n: h2},
+			&Element{n: h3},
+		}
+		v := Arrange(nt, es...)
+		for _, e := range es {
+			if e.n.IsInline() != (d == "inline") {
+				t.Fatalf("%+v", e)
+			}
+		}
+		if d == "inline" {
+			b := v.UI.(*duit.Box)
+			if len(b.Kids) != 3 {
+				t.Fatalf("%+v", b)
+			}
+		} else {
+			if g := v.UI.(*duit.Grid); g.Columns != 1 || len(g.Kids) != 3 {
+				t.Fatalf("%+v", g)
+			}
+		}
+	}
 }
 
 func TestLinkedUrl(t *testing.T) {
--- a/package.rc
+++ b/package.rc
@@ -2,6 +2,7 @@
 
 rm -rf ./$name
 mkdir ./$name
+mkdir -p ./packages
 chmod +t ./$name
 mkdir ./$name/domino-lib
 
@@ -18,7 +19,7 @@
 cp README.md ./$name/
 cp normalize.css ./$name/
 dircp domino-lib ./$name/domino-lib
-tarball=`{pwd} ^ '/' ^ $name ^ '-v0.0.1-' ^ `{date -i} ^ '-' ^ `{cat /mnt/git/branch/heads/master/hash | read -c 6} ^ '.tgz'
+tarball=`{pwd} ^ '/packages/' ^ $name ^ '-v0.0.1-' ^ `{date -i} ^ '-' ^ `{cat /mnt/git/branch/heads/master/hash | read -c 6} ^ '.tgz'
 tar czf $tarball $name
 chmod +t $tarball
 echo Created $tarball
--- a/style/stylesheets.go
+++ b/style/stylesheets.go
@@ -42,7 +42,7 @@
   display: inline-block;
 }
 
-h1, h2, h3, h4. h5, h6, div, center, frame, frameset, p, ul, menu, pre, dir {
+h1, h2, h3, h4. h5, h6, div, center, frame, frameset, p, ul, menu, pre, dir, dl, dd, dt {
 	display: block;
 }