Skip to content

Latest commit

 

History

History
81 lines (53 loc) · 2.28 KB

README.md

File metadata and controls

81 lines (53 loc) · 2.28 KB

Though, I might have used a million times, when implementing it I had a chance to sidestep and understand UTF8 encodings, multi-byte characters, encoding of emoj with zero with joiners, the unix definition of a POSIX text file

The solution is nothing fancy, very simple and haven't invested time to make it efficient, but as I move forward with the another exercises I might take up them (Why not benchmark, etc for fun)

Solution

The code is structured under wc and implementation is straightforward due Golang

Usage

 ./wc --help
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.

Usage:
  wc [flags]

Flags:
  -c, --bytes     bytes count output
  -m, --chars     char count output
  -h, --help      help for wc
  -l, --lines     line count output
  -v, --verbose   verbose output
  -V, --version   version output
  -w, --words     word count output

Example(s)

Checking the input text mentioned in the challenge step zero

The output from wc (GNU Coreutils) 8.32 on Ubuntu with (LC_NAME=sv_SE.UTF-8)

wc tests/testdata/test.txt
7145  58164 342147 tests/testdata/test.txt

The output from wc.py for the same test.txt,

./wc tests/testdata/test.txt
 7145  58164 342147 tests/testdata/test.txt

A sample run for stdin,

echo -n "TwoLines\n\n" | ./wc
 2      1       10      /dev/stdin

The output for the various options are same as that of the wc tool and it is verified using both Go tests and Functional tests

Development

The module is called wc and it uses cobra package for command line parsing, the logic is implemented in the package named util

Build

go build -o ./wc .

Unit tests

To run the tests,

go test -v ./...

Checkout the specific util package to see the various inputs it uses.

Function tests

The testdata is used which to compare alignment with wc to run the test use test.sh.