vertical-tab
parent
230937cb2e
commit
cb88f405d8
|
@ -5,6 +5,7 @@ Package **eol** implements tools for working with end-of-line, for the Go progra
|
||||||
The end-of-line sequences it supports is:
|
The end-of-line sequences it supports is:
|
||||||
|
|
||||||
* `"\n" // line-feed (LF)`
|
* `"\n" // line-feed (LF)`
|
||||||
|
* `"\v" // vertical-tab (VT)`
|
||||||
* `"\n\r" // line-feed (LF), carriage-return (CR)`
|
* `"\n\r" // line-feed (LF), carriage-return (CR)`
|
||||||
* `"\r" // carriage-return (CR)`
|
* `"\r" // carriage-return (CR)`
|
||||||
* `"\r\n" // carriage-return (CR), line-feed (LF)`
|
* `"\r\n" // carriage-return (CR), line-feed (LF)`
|
||||||
|
|
|
@ -28,6 +28,8 @@ import (
|
||||||
//
|
//
|
||||||
// var circumstance internalCircumstance = specifyCircumstance(opt.Something]("\n"), 1)
|
// var circumstance internalCircumstance = specifyCircumstance(opt.Something]("\n"), 1)
|
||||||
//
|
//
|
||||||
|
// var circumstance internalCircumstance = specifyCircumstance(opt.Something]("\v"), 1)
|
||||||
|
//
|
||||||
// var circumstance internalCircumstance = specifyCircumstance(opt.Something]("\r"), 1)
|
// var circumstance internalCircumstance = specifyCircumstance(opt.Something]("\r"), 1)
|
||||||
//
|
//
|
||||||
// var circumstance internalCircumstance = specifyCircumstance(opt.Something]("\r\n"), 1)
|
// var circumstance internalCircumstance = specifyCircumstance(opt.Something]("\r\n"), 1)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"sourcecode.social/reiver/go-eol/lf"
|
"sourcecode.social/reiver/go-eol/lf"
|
||||||
"sourcecode.social/reiver/go-eol/ls"
|
"sourcecode.social/reiver/go-eol/ls"
|
||||||
"sourcecode.social/reiver/go-eol/nel"
|
"sourcecode.social/reiver/go-eol/nel"
|
||||||
|
"sourcecode.social/reiver/go-eol/vt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ error = internalNotFoundError{}
|
var _ error = internalNotFoundError{}
|
||||||
|
@ -46,6 +47,12 @@ func (receiver internalNotFoundError) Error() string {
|
||||||
s = fmt.Sprintf(`eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line sequence %q character №%d — instead found %q (%U)`, sequence, characterNumber, actual, actual)
|
s = fmt.Sprintf(`eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line sequence %q character №%d — instead found %q (%U)`, sequence, characterNumber, actual, actual)
|
||||||
})
|
})
|
||||||
p = append(p, s...)
|
p = append(p, s...)
|
||||||
|
case vt.Rune:
|
||||||
|
var s string = fmt.Sprintf(`eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence character №%d — instead found %q (%U)`, characterNumber, actual, actual)
|
||||||
|
eolSequence.WhenSomething(func(sequence string){
|
||||||
|
s = fmt.Sprintf(`eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence %q character №%d — instead found %q (%U)`, sequence, characterNumber, actual, actual)
|
||||||
|
})
|
||||||
|
p = append(p, s...)
|
||||||
case cr.Rune:
|
case cr.Rune:
|
||||||
var s string = fmt.Sprintf(`eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line sequence character №%d — instead found %q (%U)`, characterNumber, actual, actual)
|
var s string = fmt.Sprintf(`eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line sequence character №%d — instead found %q (%U)`, characterNumber, actual, actual)
|
||||||
eolSequence.WhenSomething(func(sequence string){
|
eolSequence.WhenSomething(func(sequence string){
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"sourcecode.social/reiver/go-eol/lfcr"
|
"sourcecode.social/reiver/go-eol/lfcr"
|
||||||
"sourcecode.social/reiver/go-eol/ls"
|
"sourcecode.social/reiver/go-eol/ls"
|
||||||
"sourcecode.social/reiver/go-eol/nel"
|
"sourcecode.social/reiver/go-eol/nel"
|
||||||
|
"sourcecode.social/reiver/go-eol/vt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReadEOL tries to read an end-of-line sequence.
|
// ReadEOL tries to read an end-of-line sequence.
|
||||||
|
@ -18,6 +19,7 @@ import (
|
||||||
// The end-of-line sequences it supports are:
|
// The end-of-line sequences it supports are:
|
||||||
//
|
//
|
||||||
// line-feed (LF) (U+000A) ('\n')
|
// line-feed (LF) (U+000A) ('\n')
|
||||||
|
// vertical-tab (VT) (U+000B) ('\v')
|
||||||
// line-feed, carriage-return ("\n\r")
|
// line-feed, carriage-return ("\n\r")
|
||||||
// carriage-return (CR) (U+000D) ('\r')
|
// carriage-return (CR) (U+000D) ('\r')
|
||||||
// carriage-return, line-feed ("\r\n")
|
// carriage-return, line-feed ("\r\n")
|
||||||
|
@ -52,6 +54,8 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error)
|
||||||
switch r0 {
|
switch r0 {
|
||||||
case lf.Rune:
|
case lf.Rune:
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
|
case vt.Rune:
|
||||||
|
return vt.String, size0, nil
|
||||||
case cr.Rune:
|
case cr.Rune:
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
case nel.Rune:
|
case nel.Rune:
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"sourcecode.social/reiver/go-eol/lfcr"
|
"sourcecode.social/reiver/go-eol/lfcr"
|
||||||
"sourcecode.social/reiver/go-eol/ls"
|
"sourcecode.social/reiver/go-eol/ls"
|
||||||
"sourcecode.social/reiver/go-eol/nel"
|
"sourcecode.social/reiver/go-eol/nel"
|
||||||
|
"sourcecode.social/reiver/go-eol/vt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadEOL(t *testing.T) {
|
func TestReadEOL(t *testing.T) {
|
||||||
|
@ -29,6 +30,11 @@ func TestReadEOL(t *testing.T) {
|
||||||
ExpectedEOL: lf.String,
|
ExpectedEOL: lf.String,
|
||||||
ExpectedSize: 1,
|
ExpectedSize: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Value: "\v",
|
||||||
|
ExpectedEOL: vt.String,
|
||||||
|
ExpectedSize: 1,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Value: "\n\r",
|
Value: "\n\r",
|
||||||
ExpectedEOL: lfcr.String,
|
ExpectedEOL: lfcr.String,
|
||||||
|
@ -62,6 +68,11 @@ func TestReadEOL(t *testing.T) {
|
||||||
ExpectedEOL: lf.String,
|
ExpectedEOL: lf.String,
|
||||||
ExpectedSize: 1,
|
ExpectedSize: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Value: "\vapple banana cherry",
|
||||||
|
ExpectedEOL: vt.String,
|
||||||
|
ExpectedSize: 1,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Value: "\n\rapple banana cherr",
|
Value: "\n\rapple banana cherr",
|
||||||
ExpectedEOL: lfcr.String,
|
ExpectedEOL: lfcr.String,
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package eol
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"sourcecode.social/reiver/go-opt"
|
||||||
|
|
||||||
|
"sourcecode.social/reiver/go-eol/vt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadVT tries to read the "\r" (i.e., carriage-return) end-of-line sequence.
|
||||||
|
//
|
||||||
|
// If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\r").
|
||||||
|
//
|
||||||
|
// If the character read is not a '\r', then ReadVT will try to unread the character.
|
||||||
|
//
|
||||||
|
// Example usage:
|
||||||
|
//
|
||||||
|
// size, err := eol.ReadVT(runescanner)
|
||||||
|
func ReadVT(runescanner io.RuneScanner) (size int, err error) {
|
||||||
|
const characterNumber uint64 = 1
|
||||||
|
var circumstance internalCircumstance = specifyCircumstance(opt.Something(vt.String), characterNumber)
|
||||||
|
return readthisrune(circumstance, runescanner, vt.Rune)
|
||||||
|
}
|
|
@ -0,0 +1,209 @@
|
||||||
|
package eol_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"sourcecode.social/reiver/go-utf8"
|
||||||
|
|
||||||
|
"sourcecode.social/reiver/go-eol"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReadVT(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct{
|
||||||
|
Value string
|
||||||
|
ExpectedSize int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Value: "\v",
|
||||||
|
ExpectedSize: 1,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: "\vapple banana cherry",
|
||||||
|
ExpectedSize: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for testNumber, test := range tests {
|
||||||
|
|
||||||
|
var reader io.Reader = strings.NewReader(test.Value)
|
||||||
|
var runescanner io.RuneScanner = utf8.NewRuneScanner(reader)
|
||||||
|
|
||||||
|
actualSize, err := eol.ReadVT(runescanner)
|
||||||
|
if nil != err {
|
||||||
|
t.Errorf("For test #%d, did not expect an error but actually got one.", testNumber)
|
||||||
|
t.Logf("ERROR: (%T) %s", err, err)
|
||||||
|
t.Logf("VALUE: %q", test.Value)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
expected := test.ExpectedSize
|
||||||
|
actual := actualSize
|
||||||
|
|
||||||
|
if expected != actual {
|
||||||
|
t.Errorf("For test #%d, the actual size is not what was expected.", testNumber)
|
||||||
|
t.Logf("EXPECTED: %d", expected)
|
||||||
|
t.Logf("ACTUAL: %d", actual)
|
||||||
|
t.Logf("VALUE: %q", test.Value)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadVT_fail(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct{
|
||||||
|
Value string
|
||||||
|
ExpectedError string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Value: "",
|
||||||
|
ExpectedError: `eol: problem reading character №1 of end-of-line sequence "\v": EOF`,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: "\n",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '\n' (U+000A)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: "\u0085",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '\u0085' (U+0085)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: "\u2028",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '\u2028' (U+2028)`,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: "😈",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '😈' (U+1F608)`,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: "\napple banana cherry",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '\n' (U+000A)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: "\u0085apple banana cherry",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '\u0085' (U+0085)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: "\u2028apple banana cherry",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '\u2028' (U+2028)`,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: "😈apple banana cherry",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '😈' (U+1F608)`,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: " \n",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found ' ' (U+0020)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: " \r",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found ' ' (U+0020)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: " \u0085",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found ' ' (U+0020)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: " \u2028",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found ' ' (U+0020)`,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: " 😈",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found ' ' (U+0020)`,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: ".\n",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '.' (U+002E)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: ".\r",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '.' (U+002E)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: ".\u0085",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '.' (U+002E)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: ".\u2028",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '.' (U+002E)`,
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
Value: ".😈",
|
||||||
|
ExpectedError: `eol: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence "\v" character №1 — instead found '.' (U+002E)`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for testNumber, test := range tests {
|
||||||
|
|
||||||
|
var reader io.Reader = strings.NewReader(test.Value)
|
||||||
|
var runescanner io.RuneScanner = utf8.NewRuneScanner(reader)
|
||||||
|
|
||||||
|
actualSize, err := eol.ReadVT(runescanner)
|
||||||
|
if nil == err {
|
||||||
|
t.Errorf("For test #%d, expected an error but did not actually get one.", testNumber)
|
||||||
|
t.Logf("EXPECTED-ERROR: %q", test.ExpectedError)
|
||||||
|
t.Logf("VALUE: %q", test.Value)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
expected := test.ExpectedError
|
||||||
|
actual := err.Error()
|
||||||
|
|
||||||
|
if expected != actual {
|
||||||
|
t.Errorf("For test #%d, the actual error is not what was expected.", testNumber)
|
||||||
|
t.Logf("EXPECTED: %q", expected)
|
||||||
|
t.Logf("ACTUAL: %q", actual)
|
||||||
|
t.Logf("VALUE: %q", test.Value)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
expected := 0
|
||||||
|
actual := actualSize
|
||||||
|
|
||||||
|
if expected != actual {
|
||||||
|
t.Errorf("For test #%d, the actual size is not what was expected.", testNumber)
|
||||||
|
t.Logf("EXPECTED: %d", expected)
|
||||||
|
t.Logf("ACTUAL: %d", actual)
|
||||||
|
t.Logf("VALUE: %q", test.Value)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
package vt
|
||||||
|
|
||||||
|
const Byte byte = '\u000B'
|
|
@ -0,0 +1,3 @@
|
||||||
|
package vt
|
||||||
|
|
||||||
|
const Rune rune = '\u000B'
|
|
@ -0,0 +1,3 @@
|
||||||
|
package vt
|
||||||
|
|
||||||
|
const String string = string(Rune)
|
Loading…
Reference in New Issue