Giter Site home page Giter Site logo

valast's Introduction

valast - convert Go values to their AST Hexops logo

Go Reference

Go CI codecov Go Report Card

Valast converts Go values at runtime into their go/ast equivalent, e.g.:

x := &foo.Bar{
    a: "hello world!",
    B: 1.234,
}
fmt.Println(valast.String(x))

Prints string:

&foo.Bar{a: "hello world!", B: 1.234}

What is this useful for?

This can be useful for debugging and testing, you may think of it as a more comprehensive and configurable version of the fmt package's %+v and %#v formatting directives. It is similar to e.g. repr in Python.

Features

  • Produces Go code via a go/ast, defers formatting to the best-in-class Go formatter gofumpt.
  • Fully handles unexported fields, types, and values (optional.)
  • Strong emphasis on being used for producing valid Go code that can be copy & pasted directly into e.g. tests.
  • Extensively tested, over 88 tests and handling numerous edge cases (such as pointers to unaddressable literal values like &"foo" properly, and even finding bugs in alternative packages').

Alternatives comparison

The following are alternatives to Valast, making note of the differences we found that let us to create Valast:

You may also wish to look at autogold and go-cmp, which aim to solve the "compare Go values in a test" problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.