Esempio n. 1
0
func ExampleWriter() {
	css := `
		// comment
		.foo {
			color: white;
		}
		`
	s, buf := scanner.New(css), bytes.Buffer{}
	w := writer.New(&buf)
	for to := s.Next(); to.Type != scanner.TokenEOF; to = s.Next() {
		w.Write(to)
	}
	if err := w.Close(); err != nil {
		fmt.Print(err)
	} else {
		fmt.Print((string)(buf.Bytes()))
	}
	// Output:
	//
	//		// comment
	//		.foo {
	//			color: white;
	//		}
	//
}
Esempio n. 2
0
func scan(css string) ([]*scanner.Token, error) {
	s := scanner.New(css)
	tks := []*scanner.Token{}
	for {
		tk := s.Next()
		switch tk.Type {
		case scanner.TokenEOF:
			return tks, nil
		case scanner.TokenError:
			return nil, errors.Input(tk.Value)
		default:
			tks = append(tks, tk)
		}
	}
}
Esempio n. 3
0
	It("BOM", func() {
		w.Write(&scanner.Token{
			Type:  scanner.TokenBOM,
			Value: "\uFEFF",
		})
		assertClose("\uFEFF")
	})

	It("Parse and Write", func() {
		css := `
		// comment
		.foo {
			color: white;
		}
		`
		s := scanner.New(css)
		for to := s.Next(); to.Type != scanner.TokenEOF; to = s.Next() {
			w.Write(to)
		}
		assertClose(css)
	})

	It("Close closable writer", func() {
		controller := gomock.NewController(t())
		defer controller.Finish()
		bufMock := NewMockWriteCloser(controller)
		bufMock.EXPECT().Close()

		w := New(bufMock)
		Ω(w.Close()).Should(Succeed())
	})