Compare commits

..

No commits in common. "4bdb41c618755e13199a94927c364191cf7cd823" and "cb88f405d8a43c0a62d4ecf64e66c2194ce989e6" have entirely different histories.

10 changed files with 15 additions and 280 deletions

View File

@ -5,9 +5,8 @@ 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)`
* `"\n\r" // line-feed (LF), carriage-return (CR)`
* `"\v" // vertical-tab (VT)` * `"\v" // vertical-tab (VT)`
* `"\f" // form-feed (FF)` * `"\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)`
* `"\u0085" // next-line (NEL)` * `"\u0085" // next-line (NEL)`

View File

@ -1,3 +0,0 @@
package ff
const Byte byte = '\u000C'

View File

@ -1,3 +0,0 @@
package ff
const Rune rune = '\u000C'

View File

@ -1,3 +0,0 @@
package ff
const String string = string(Rune)

View File

@ -6,7 +6,6 @@ import (
"sourcecode.social/reiver/go-opt" "sourcecode.social/reiver/go-opt"
"sourcecode.social/reiver/go-eol/cr" "sourcecode.social/reiver/go-eol/cr"
"sourcecode.social/reiver/go-eol/ff"
"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"
@ -54,12 +53,6 @@ func (receiver internalNotFoundError) Error() 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) 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...) p = append(p, s...)
case ff.Rune:
var s string = fmt.Sprintf(`eol: form-feed (FF) character ('\f') (U+000C) 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: form-feed (FF) character ('\f') (U+000C) 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){

View File

@ -7,7 +7,6 @@ import (
"sourcecode.social/reiver/go-eol/cr" "sourcecode.social/reiver/go-eol/cr"
"sourcecode.social/reiver/go-eol/crlf" "sourcecode.social/reiver/go-eol/crlf"
"sourcecode.social/reiver/go-eol/ff"
"sourcecode.social/reiver/go-eol/lf" "sourcecode.social/reiver/go-eol/lf"
"sourcecode.social/reiver/go-eol/lfcr" "sourcecode.social/reiver/go-eol/lfcr"
"sourcecode.social/reiver/go-eol/ls" "sourcecode.social/reiver/go-eol/ls"
@ -20,9 +19,8 @@ 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')
// line-feed, carriage-return ("\n\r")
// vertical-tab (VT) (U+000B) ('\v') // vertical-tab (VT) (U+000B) ('\v')
// vertical-tab (VT) (U+000B) ('\f') // 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")
// next-line (NEL) (U+0085) // next-line (NEL) (U+0085)
@ -58,8 +56,6 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error)
// Nothing here. // Nothing here.
case vt.Rune: case vt.Rune:
return vt.String, size0, nil return vt.String, size0, nil
case ff.Rune:
return ff.String, size0, nil
case cr.Rune: case cr.Rune:
// Nothing here. // Nothing here.
case nel.Rune: case nel.Rune:

View File

@ -11,7 +11,6 @@ import (
"sourcecode.social/reiver/go-eol" "sourcecode.social/reiver/go-eol"
"sourcecode.social/reiver/go-eol/cr" "sourcecode.social/reiver/go-eol/cr"
"sourcecode.social/reiver/go-eol/crlf" "sourcecode.social/reiver/go-eol/crlf"
"sourcecode.social/reiver/go-eol/ff"
"sourcecode.social/reiver/go-eol/lf" "sourcecode.social/reiver/go-eol/lf"
"sourcecode.social/reiver/go-eol/lfcr" "sourcecode.social/reiver/go-eol/lfcr"
"sourcecode.social/reiver/go-eol/ls" "sourcecode.social/reiver/go-eol/ls"
@ -31,20 +30,15 @@ func TestReadEOL(t *testing.T) {
ExpectedEOL: lf.String, ExpectedEOL: lf.String,
ExpectedSize: 1, ExpectedSize: 1,
}, },
{
Value: "\n\r",
ExpectedEOL: lfcr.String,
ExpectedSize: 2,
},
{ {
Value: "\v", Value: "\v",
ExpectedEOL: vt.String, ExpectedEOL: vt.String,
ExpectedSize: 1, ExpectedSize: 1,
}, },
{ {
Value: "\f", Value: "\n\r",
ExpectedEOL: ff.String, ExpectedEOL: lfcr.String,
ExpectedSize: 1, ExpectedSize: 2,
}, },
{ {
Value: "\r", Value: "\r",
@ -74,38 +68,33 @@ func TestReadEOL(t *testing.T) {
ExpectedEOL: lf.String, ExpectedEOL: lf.String,
ExpectedSize: 1, ExpectedSize: 1,
}, },
{
Value: "\n\rapple banana cherry",
ExpectedEOL: lfcr.String,
ExpectedSize: 2,
},
{ {
Value: "\vapple banana cherry", Value: "\vapple banana cherry",
ExpectedEOL: vt.String, ExpectedEOL: vt.String,
ExpectedSize: 1, ExpectedSize: 1,
}, },
{ {
Value: "\fapple banana cherry", Value: "\n\rapple banana cherr",
ExpectedEOL: ff.String, ExpectedEOL: lfcr.String,
ExpectedSize: 1, ExpectedSize: 2,
}, },
{ {
Value: "\rapple banana cherry", Value: "\rapple banana cherr",
ExpectedEOL: cr.String, ExpectedEOL: cr.String,
ExpectedSize: 1, ExpectedSize: 1,
}, },
{ {
Value: "\r\napple banana cherry", Value: "\r\napple banana cherr",
ExpectedEOL: crlf.String, ExpectedEOL: crlf.String,
ExpectedSize: 2, ExpectedSize: 2,
}, },
{ {
Value: "\u0085apple banana cherry", Value: "\u0085apple banana cherr",
ExpectedEOL: nel.String, ExpectedEOL: nel.String,
ExpectedSize: 2, ExpectedSize: 2,
}, },
{ {
Value: "\u2028apple banana cherry", Value: "\u2028apple banana cherr",
ExpectedEOL: ls.String, ExpectedEOL: ls.String,
ExpectedSize: 3, ExpectedSize: 3,
}, },

View File

@ -1,24 +0,0 @@
package eol
import (
"io"
"sourcecode.social/reiver/go-opt"
"sourcecode.social/reiver/go-eol/ff"
)
// ReadFF tries to read the "\f" (i.e., form-feed) end-of-line sequence.
//
// If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\f").
//
// If the character read is not a '\f', then ReadFF will try to unread the character.
//
// Example usage:
//
// size, err := eol.ReadFF(runescanner)
func ReadFF(runescanner io.RuneScanner) (size int, err error) {
const characterNumber uint64 = 1
var circumstance internalCircumstance = specifyCircumstance(opt.Something(ff.String), characterNumber)
return readthisrune(circumstance, runescanner, ff.Rune)
}

View File

@ -1,209 +0,0 @@
package eol_test
import (
"testing"
"io"
"strings"
"sourcecode.social/reiver/go-utf8"
"sourcecode.social/reiver/go-eol"
)
func TestReadFF(t *testing.T) {
tests := []struct{
Value string
ExpectedSize int
}{
{
Value: "\f",
ExpectedSize: 1,
},
{
Value: "\fapple 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.ReadFF(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 TestReadFF_fail(t *testing.T) {
tests := []struct{
Value string
ExpectedError string
}{
{
Value: "",
ExpectedError: `eol: problem reading character №1 of end-of-line sequence "\f": EOF`,
},
{
Value: "\n",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '\n' (U+000A)`,
},
{
Value: "\u0085",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '\u0085' (U+0085)`,
},
{
Value: "\u2028",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '\u2028' (U+2028)`,
},
{
Value: "😈",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '😈' (U+1F608)`,
},
{
Value: "\napple banana cherry",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '\n' (U+000A)`,
},
{
Value: "\u0085apple banana cherry",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '\u0085' (U+0085)`,
},
{
Value: "\u2028apple banana cherry",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '\u2028' (U+2028)`,
},
{
Value: "😈apple banana cherry",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '😈' (U+1F608)`,
},
{
Value: " \n",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found ' ' (U+0020)`,
},
{
Value: " \r",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found ' ' (U+0020)`,
},
{
Value: " \u0085",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found ' ' (U+0020)`,
},
{
Value: " \u2028",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found ' ' (U+0020)`,
},
{
Value: " 😈",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found ' ' (U+0020)`,
},
{
Value: ".\n",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '.' (U+002E)`,
},
{
Value: ".\r",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '.' (U+002E)`,
},
{
Value: ".\u0085",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '.' (U+002E)`,
},
{
Value: ".\u2028",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" character №1 — instead found '.' (U+002E)`,
},
{
Value: ".😈",
ExpectedError: `eol: form-feed (FF) character ('\f') (U+000C) not found for end-of-line sequence "\f" 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.ReadFF(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
}
}
}
}

View File

@ -8,11 +8,11 @@ import (
"sourcecode.social/reiver/go-eol/vt" "sourcecode.social/reiver/go-eol/vt"
) )
// ReadVT tries to read the "\v" (i.e., carriage-return) end-of-line sequence. // 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 "\v"). // If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\r").
// //
// If the character read is not a '\v', then ReadVT will try to unread the character. // If the character read is not a '\r', then ReadVT will try to unread the character.
// //
// Example usage: // Example usage:
// //