|
1 | 1 | package fixedlength
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "io" |
4 | 5 | "strings"
|
5 | 6 | "testing"
|
6 | 7 |
|
7 | 8 | "github.com/bradleyjkemp/cupaloy"
|
8 | 9 | "github.com/jf-tech/go-corelib/jsons"
|
9 | 10 | "github.com/jf-tech/go-corelib/strs"
|
| 11 | + "github.com/jf-tech/go-corelib/testlib" |
10 | 12 | "github.com/stretchr/testify/assert"
|
11 | 13 |
|
12 | 14 | "github.com/jf-tech/omniparser/errs"
|
13 | 15 | "github.com/jf-tech/omniparser/extensions/omniv21/transform"
|
| 16 | + "github.com/jf-tech/omniparser/idr" |
14 | 17 | )
|
15 | 18 |
|
16 | 19 | func TestValidateSchema(t *testing.T) {
|
@@ -304,10 +307,29 @@ func TestValidateSchema(t *testing.T) {
|
304 | 307 | }
|
305 | 308 |
|
306 | 309 | func TestCreateFormatReader(t *testing.T) {
|
307 |
| - _, err := NewFixedLengthFileFormat("test").CreateFormatReader( |
308 |
| - "test-input", |
309 |
| - strings.NewReader("TODO"), |
310 |
| - &fixedLengthFormatRuntime{}) |
| 310 | + r, err := NewFixedLengthFileFormat("test").CreateFormatReader( |
| 311 | + "test", |
| 312 | + strings.NewReader("abcd\n1234\n"), |
| 313 | + &fixedLengthFormatRuntime{ |
| 314 | + Decl: &fileDecl{ |
| 315 | + Envelopes: []*envelopeDecl{ |
| 316 | + { |
| 317 | + Name: strs.StrPtr("env1"), |
| 318 | + ByRows: testlib.IntPtr(2), |
| 319 | + Columns: []*columnDecl{ |
| 320 | + {Name: "letters", StartPos: 1, Length: 3, LinePattern: strs.StrPtr("^[a-z]")}, |
| 321 | + {Name: "numerics", StartPos: 1, Length: 3, LinePattern: strs.StrPtr("^[0-9]")}, |
| 322 | + }, |
| 323 | + }, |
| 324 | + }, |
| 325 | + }, |
| 326 | + }) |
| 327 | + assert.NoError(t, err) |
| 328 | + n, err := r.Read() |
311 | 329 | assert.NoError(t, err)
|
312 |
| - // TODO |
| 330 | + assert.Equal(t, `{"letters":"abc","numerics":"123"}`, idr.JSONify2(n)) |
| 331 | + r.Release(n) |
| 332 | + n, err = r.Read() |
| 333 | + assert.Equal(t, io.EOF, err) |
| 334 | + assert.Nil(t, n) |
313 | 335 | }
|
0 commit comments