Skip to content

Commit

Permalink
Skip non-existent families and weights
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredxing committed Oct 25, 2015
1 parent 3c16791 commit 025da86
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions brick.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
}

for _, weight := range weights {
// Verify that variant exists, else move on
if _, exists := fonts[family][weight]; !exists {
continue
}

var uri bytes.Buffer

// Local font URI
Expand Down
40 changes: 40 additions & 0 deletions brick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,46 @@ func TestFamilies(t *testing.T) {
}
}

// Tests a request including non-existing variants
func TestNonexistentVariant(t *testing.T) {
res := httptest.NewRecorder()

req, err := http.NewRequest("GET", "http://brick.im/Open+Sans:400,800", nil)
if err != nil {
t.Fatal(err)
}

handler(res, req)
if res.Code != 200 {
t.Fail()
}

var expected = formatRule("Open Sans", "normal", "400", "Open Sans Regular", "opensans", "400")
if res.Body.String() != expected {
t.Fail()
}
}

// Tests a request including non-existing families
func TestNonexistentFamily(t *testing.T) {
res := httptest.NewRecorder()

req, err := http.NewRequest("GET", "http://brick.im/Foo+Sans:400/Open+Sans:400", nil)
if err != nil {
t.Fatal(err)
}

handler(res, req)
if res.Code != 200 {
t.Fail()
}

var expected = formatRule("Open Sans", "normal", "400", "Open Sans Regular", "opensans", "400")
if res.Body.String() != expected {
t.Fail()
}
}

// Tests a request using the force flag (preventing the browser from
// loading the font from the local computer)
func TestForce(t *testing.T) {
Expand Down

0 comments on commit 025da86

Please sign in to comment.