question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a mechanism for converting user input to custom types

See original GitHub issue

For writing our own exercises and specially for third party libraries’ exercises we need a way to specify how to convert an input string from the user to an arbitrary type. Built-in types like String or Int are supported but we often have exercises like this:

def anExercise(res0: Xor.Right[String, Int]) = {
  val right: String Xor Int = Xor.Right(42)
  right should be(res0)
}

We can’t currently convert an user-provided input to a cats.data.Xor and we should be able to do so. Same for the every type constructors that cats or other libraries provide.

Another case that we don’t handle currently is referring to an identifier, see the following example:

def anExercise(res0: ?) = {
  val one = 1
  val anotherOne = 1
  (one == res0) should be(true)
}

Here, we expect the user to insert anotherOne. The problem is that we don’t want to treat res0’s content as a string but an identifier that will be resolved to the value it refers to at runtime.

@andyscott feel free to split this into separate issues if you think they should be tackled separately.

@raulraja @rafaparadela @juanpedromoreno feel free to add your comments.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
andyscottcommented, Mar 17, 2016

Will do. I’m in the process of bringing back and rewriting some code from a month ago that addresses this properly.

1reaction
raulrajacommented, Mar 17, 2016

@andyscott Regarding A. We need to get user input refering to lib types working. I tested that if for example I change…

      ...map { case (arg, tpe) ⇒
        catching(toolbox.parse(arg),
          s"Unable to parse arg $arg") >>= { parsedArg ⇒
        catching(toolbox.eval(Typed(parsedArg, tq"$tpe")),
          s"Unable to evaluate arg $arg as $tpe")
      }}

for

      ...map { case (args, tpe) ⇒
        val arg = s"{ import shapeless._; $args}"
        catching(toolbox.parse(arg),
          s"Unable to parse arg $arg") >>= { parsedArg ⇒
        catching(toolbox.eval(Typed(parsedArg, tq"$tpe")),
          s"Unable to evaluate arg $arg as $tpe")
      }}

All the shapeless types immediately work. For the time being we should allow at the Lib level provide a set of imports that will be evaluated with each lib exercise along with the user input.

We need to get this working now because it’s preventing from actually properly testing the UI input when trying to reproduce the user experience completing the exercises.

Let’s make this change a high priority.

Read more comments on GitHub >

github_iconTop Results From Across the Web

12.3 Input value conversion 6.x - Apache
In order to convert its input a FormComponent must know the type of its model object. This parameter can be explicitly set with...
Read more >
6 Validating and Converting Input - Oracle Help Center
This chapter describes how to add conversion and validation capabilities to ADF Faces input components in your application. It also describes how to...
Read more >
Type Conversion in C - GeeksforGeeks
Type conversion in C is the process of converting one data type to another. The type conversion is only performed to those data...
Read more >
How to use ControlValueAccessor to enhance date input with ...
Set the selector to input[type=date] - This will add the conversion mechanism and validations to all date-inputs without any extra effort.
Read more >
Converting String to a user-defined type. Input-Output issue
The function readLn does what you want, because it converts the input string to the correct type as long as the type has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found