Skip to content
This repository has been archived by the owner on May 14, 2023. It is now read-only.

Commit

Permalink
Add fuzzing to the transform package
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Aug 13, 2019
1 parent a179b97 commit 2c92aac
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
27 changes: 24 additions & 3 deletions .travis.yml
@@ -1,12 +1,33 @@
dist: bionic
language: go
go:
- 1.7
- 1.8
- "1.11"

services:
- docker

before_install:
- go get github.com/mattn/goveralls

install:
- make setup
- make build

script:
- make test
- bash scripts/cover.sh
# Coveralls is down for maintenance currently
# - bash scripts/cover.sh

jobs:
include:
- stage: Build, Unit-Tests & Fuzz-Tests
if: branch = master AND type IN (pull_request)
go: 1.12.x
script:
- bash scripts/fuzzit.sh regression

- stage: Fuzzit (Fuzzing)
if: branch = master AND type IN (push)
go: 1.12.x
script:
- bash scripts/fuzzit.sh fuzzing
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# prose [![Build Status](https://travis-ci.org/jdkato/prose.svg?branch=master)](https://travis-ci.org/jdkato/prose) [![Build status](https://ci.appveyor.com/api/projects/status/24bepq85nnnk4scr/branch/v2?svg=true)](https://ci.appveyor.com/project/jdkato/prose/branch/v2) [![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/gopkg.in/jdkato/prose.v2) [![Coverage Status](https://coveralls.io/repos/github/jdkato/prose/badge.svg?branch=v2)](https://coveralls.io/github/jdkato/prose?branch=v2) [![Go Report Card](https://goreportcard.com/badge/github.com/jdkato/prose)](https://goreportcard.com/report/github.com/jdkato/prose) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go#natural-language-processing)
# prose [![Build Status](https://travis-ci.org/jdkato/prose.svg?branch=master)](https://travis-ci.org/jdkato/prose) [![fuzzit](https://app.fuzzit.dev/badge?org_id=prose=master)](https://fuzzit.dev) [![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/gopkg.in/jdkato/prose.v2) [![Coverage Status](https://coveralls.io/repos/github/jdkato/prose/badge.svg?branch=v2)](https://coveralls.io/github/jdkato/prose?branch=v2) [![Go Report Card](https://goreportcard.com/badge/github.com/jdkato/prose)](https://goreportcard.com/report/github.com/jdkato/prose) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go#natural-language-processing)


`prose` is a natural language processing library (English only) in *pure Go*. It supports tokenization, segmentation, part-of-speech tagging, and named-entity extraction.
Expand Down
30 changes: 30 additions & 0 deletions scripts/fuzzit.sh
@@ -0,0 +1,30 @@
#!/bin/bash
#
# Helper script for working with fuzzit.dev:
#
# https://github.com/fuzzitdev/example-go
#
# Based on:
#
# https://github.com/google/syzkaller/blob/master/fuzzit.sh
set -eux

function target {
go-fuzz-build -libfuzzer -func $3 -o fuzzer.a $2
clang -fsanitize=fuzzer fuzzer.a -o fuzzer

./fuzzit create target $1 || true
./fuzzit create job $LOCAL --type fuzzing --branch $TRAVIS_BRANCH --revision $TRAVIS_COMMIT prose/$1 ./fuzzer
}

go get -u github.com/dvyukov/go-fuzz/go-fuzz-build
wget -q -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/v2.4.12/fuzzit_Linux_x86_64
chmod a+x fuzzit
if [ "$1" = "fuzzing" ]; then
./fuzzit auth $FUZZIT_API_KEY
export LOCAL=""
else
export LOCAL="--local"
fi

target prose-transform ./transform Fuzz
6 changes: 5 additions & 1 deletion transform/transform.go
Expand Up @@ -78,5 +78,9 @@ func Camel(s string) string {
break
}
}
return strings.TrimSpace(string(unicode.ToLower(first)) + Pascal(s)[1:])
body := Pascal(s)
if len(body) > 1 {
return strings.TrimSpace(string(unicode.ToLower(first)) + body[1:])
}
return s
}
22 changes: 22 additions & 0 deletions transform/transform_fuzz.go
@@ -0,0 +1,22 @@
// +build gofuzz

package transform

func Fuzz(data []byte) int {
s := string(data)

// Case transformations
Simple(s)
Snake(s)
Dash(s)
Dot(s)
Constant(s)
Pascal(s)
Camel(s)

// Title converters
tc := NewTitleConverter(APStyle)
tc.Title(s)

return 0
}

0 comments on commit 2c92aac

Please sign in to comment.