Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Convert Go values to their AST

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

hexops/valast

Go Reference

Go CIcodecovGo Report Card

Valast converts Go values at runtime into theirgo/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 thefmt package's%+v and%#v formatting directives. It is similar to e.g.repr in Python.

Features

  • Produces Go code via ago/ast, defers formatting to the best-in-class Go formattergofumpt.
  • 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 evenfinding bugs in alternative packages').
  • Provide custom AST representations for your types withvalast.RegisterType(...).

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 atautogold andgo-cmp, which aim to solve the "compare Go values in a test" problem.

About

Convert Go values to their AST

Topics

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Sponsor this project

    Languages


    [8]ページ先頭

    ©2009-2025 Movatter.jp