Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add destructure structs feature #3

Merged
merged 2 commits into from
Dec 12, 2016

Conversation

muhifauzan
Copy link
Contributor

Closes #2.

@muhifauzan
Copy link
Contributor Author

muhifauzan commented Dec 10, 2016

Need help beforehand, @danielberkompas how to move the test do doctest for this case? I try to move the module definition for Person but no luck. Seems like the module definition in doctest doesn't reference the module in the test namespace, and use the lib namespace instead.

@danielberkompas
Copy link
Owner

@muhifauzan Try this?

defmodule DestructureTest do
  use ExUnit.Case

  import Destructure

  defmodule Person do
    defstruct [:name, :email]
  end

  doctest Destructure

  test "destructure a simple structs" do
    d(%Person{name}) = %Person{name: "Joe"}
    assert name == "Joe"
  end

  test "destructure a simple struct with custom variable naming" do
    d(%Person{name, email: mail}) = %Person{name: "Joe", email: "[email protected]"}
    assert {name, mail} == {"Joe", "[email protected]"}
  end
end

Defining the Person module above the doctest call should make it available in doctests.

@muhifauzan
Copy link
Contributor Author

Ah, I see. I'll try to implement that later.

@muhifauzan muhifauzan changed the title [WIP] Add destructure structs feature Add destructure structs feature Dec 11, 2016
@muhifauzan
Copy link
Contributor Author

@danielberkompas please have a look.

@danielberkompas
Copy link
Owner

Looks great! Thanks! ⭐

@danielberkompas danielberkompas merged commit ab353d0 into danielberkompas:master Dec 12, 2016
@muhifauzan muhifauzan deleted the struct-support branch December 12, 2016 02:22
@Havvy
Copy link

Havvy commented Dec 12, 2016

Thanks!

@muhifauzan
Copy link
Contributor Author

Anytime 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants