Skip to content

Need a full set of encoding tests #3488

Closed

Description

@iSazonov

Now we don't have a full set of encoding tests (only for redirections). We need to create them during future Encoding RFC implementation (?).

In #3467 (discussion Issue #3248) we fix Default/OEM encoding behavior PowerShell Core on Windows (as in Windows PowerShell) but don't add tests (waiting the RFC). The simplest test (from Michael Klement (@mklement0)) is:

# Setup:
# Create a no-BOM UTF-8 file with the following literal content:
#   'ö' 
# which, when executed as a PS script, should echo 'ö' back, IF the script
# was correctly decoded from UTF-8 by PS.
# UTF-8 bytes: 0x27 (single quote), 0xc3 0xb6 (encoding of 'ö', U+00F6), 0x27 (single quote)
[byte[]] (0x27, 0xc3, 0xb6, 0x27) | Set-Content -Encoding Byte /tmp/$PID.ps1

# Test: See if the 'ö' is echoed back correctly.
#       Should return $True
'ö' -eq (& /tmp/$PID.ps1)

We need test for:

Activity

  1. mklement0 commented on Apr 5, 2017

    @mklement0
    Contributor

    Ilya (@iSazonov):

    The test snippet tests how PowerShell itself reads source code that has no BOM, so can you please add that as a separate action item (check box) to the list of tests?
    (Perhaps that behavior is implied by the other tests, but I think it should still be a separate one.)

    (And, on a more quibbly note: Can you add the word "character" before "encoding" to the title, so that it's clear what kind of encoding is being referred to?)

    And here are the Set-Content / Get-Content test snippets with BOM-less UTF-8 encoding in effect:

    # Setup: *create* a  BOM-less UTF-8 file.
    'ö' | set-content -nonewline /tmp/$pid.txt
    
    # Tests: Both should output $True
    
    # Compare the raw bytes of the new file to the UTF-8 encoding of 'ö' (0xc3 0xb6)
    # With the current alpha17, this would return $False, because Set-Content creates an
    # ISO-8859-1 file.
    $null -eq (Compare-Object (Get-Content -Encoding Byte -Raw /tmp/$pid.txt) (0xc3, 0xb6))
    
    # See if the BOM-less UTF-8 file is *read* correctly.
    'ö' -eq (Get-Content -Raw /tmp/$pid.txt)
  2. iSazonov commented on Apr 5, 2017

    @iSazonov
    CollaboratorAuthor

    We have never used "character" before so it can confuse us even more. (?)

  3. mklement0 commented on Apr 5, 2017

    @mklement0
    Contributor

    Ilya (@iSazonov):

    Not that it will matter much in this instance, but just for the record and for future instances where the distinction may matter:

    We are discussing character encodings here.

    Encoding is a far more generic term, of which character encoding is just one instance.

    Given that the issues in this repo span all sorts of topics, giving sufficient context is preferable.

    P.S.: In light of the above, I would have preferred the title "Default Character Encoding" for the RFC.

  4. iSazonov commented on Apr 5, 2017

    @iSazonov
    CollaboratorAuthor

    Michael Klement (@mklement0) In the code we use "encoding". So let us defer the question to the discretion of the mantainers.

  5. mklement0 commented on Apr 5, 2017

    @mklement0
    Contributor

    Ilya (@iSazonov):

    Sounds good.

    It's perfectly understandable to shorten "character encoding" to "encoding" in a given, narrow context, where there's no risk of ambiguity.

    My only point is that in a larger context the added specificity can be helpful - both for searching topics by keywords and for quick comprehension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugWG-Quality-Testissues in a test or in test infrastructure

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions