Skip to content

Python: type-sensitivity in expectSelfie #333

@nedtwigg

Description

@nedtwigg

Here are our docs for now:

Let's say we have the following test code:
```python
expectSelfie(str([1, 2, 3])).toBe_TODO()
```
If you run this test, selfie will rewrite your sourcecode to be this:
```python
expectSelfie(str([1, 2, 3])).toBe("[1, 2, 3]")
```

Inside of expectSelfie, we can switch on the object type to return primitives, for example

class IntSelfie(private val actual: Int) {
@JvmOverloads fun toBe_TODO(unusedArg: Any? = null) = toBeDidntMatch(null, actual, LiteralInt)
fun toBe(expected: Int) =
if (actual == expected) Selfie.system.checkSrc(actual)
else toBeDidntMatch(expected, actual, LiteralInt)
}

But for other things like an array or FooPerson, we have some design choices to make. We should probably call either __str__ or __repr__ on the object. I'm leaning towards __repr__.

https://chat.openai.com/share/b438ed63-4796-4418-89e1-eb055042e786

TBD!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions